I am new to Redux and I have a problem. I have an array of objects in state, after adding a new object to this array I want to change all other objects. For example, something like this:
[{id : 0, visible: false}, {id : 1, visible: true}] - old array [{id : 0, visible: false}, {id : 1, visible : false}, {id : 2, visible : true}] - that I want
Where should I prepare the old state? As the reduction document said, in the gearboxes I should not do anything with the state, I just need to return a new state. Can I write functions in reducers that will prepare a copy of the previous state and return as a new state? Sort of:
export function ui(state = initialState, action){ switch (action.type){ case "SOME_ACTION" : var newState = someFunction(state.items, action) return Object.assign({}, state, { items : newState }); default: return state; }} function someFunction(array, action){ .... some code return newArray }
Or should I keep this feature elsewhere? What are the best able data editing techniques?
source share