Answer the question
In order to leave comments, you need to log in
How to change the state in the reducer?
Hey! This is my reducer
const initialState = {
items: {
First: 0,
Second: 0,
Third: 0
},
sum: 0
}
export default function fwReducer(state = initialState, action) {
switch (action.type) {
case ('INC '): {
const name = action.payload;
let newState = { ...state };
newState.items[name] += 1;
return { items: {...newState.items }, sum: state.total+1};
}
default: return state
}
}
I understand that now I am changing the state incorrectly, + in fact I am changing the array in the original store, mutating it, which is impossible. How should it be? Help me please)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question