Skip to content Skip to sidebar Skip to footer

Update The Redux State In The Reducer Having Array Of Objects

I am new to the react-redux. I do have an object which is like, const initialState = { Low: [ { id: 0, technologyId: 0,

Solution 1:

Because you use the original state object and return a modified version of it (i.e. you do affect your initialState).

You must create a copy of the state in your reducer, for example

caseQUIZ_DATA:
  returnObject.assign(
    {},
    state,
    {
      Low: action.data,
      error: false
    }
  )
caseRESET_SETUP_QUIZ: {
  returnObject.assign(
    {},
    state
  )
}

You have dedicated librairies like immutablejs to handle this (https://redux.js.org/recipes/usingimmutablejs)

Post a Comment for "Update The Redux State In The Reducer Having Array Of Objects"