redux array reducer code example
Example 1: redux reducer
const Reducer = (state=[],action) =>{
switch(action.type){
case'add':
return [...state,action.payload]
default:
return state ;
}
}
Example 2: js immutable update object
function updateVeryNestedField(state, action) {
return {
...state,
first: {
...state.first,
second: {
...state.first.second,
[action.someId]: {
...state.first.second[action.someId],
fourth: action.someValue
}
}
}
}
}