Ad

Redux State Set Object To Object

- 1 answer

i have initial state like:

let initialState = {
   items: [
      {
        name: 'a'
      },
      {
        name: 'b'
      }
   ],
   otherItems: []
}

i'm trying to copy items and make it otherItems so otherItems will be same with items in case SET_OBJECT

case: SET_OBJECT
  return {
   ...state, 
   otherItems: items
  }

i tried this but not worked. I'm getting error items is not defined

Ad

Answer

You code should be like this

case: SET_OBJECT: 
  return {
   ...state, 
   otherItems: initialState.items
  }
Ad
source: stackoverflow.com
Ad