P
P
pandaa2020-06-13 10:21:52
redux
pandaa, 2020-06-13 10:21:52

Adding a new object to state, is it a mutation?

I want to make something like a stack where new data will be added:

case SET_STACK:
  state[action.name] = {
    use: action.use,
    title: action.title,
    tab: action.tab
  }
  return state

But is it possible to do this in redux? Is this a mutation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alex4answ, 2020-06-13
@pandaa

This is a mutation, you must return a new state.
make a stack history of the state and that's it, and in the store always return the new state

X
xenonhammer, 2020-06-18
@xenonhammer

Use for example

return {...state ,
   use: action.use,
    title: action.title,
    tab: action.tab
}

This is a clone of the state, with new values

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question