I was learning Redux and I faced some confusion with how reducer updates the state. For example here is the code:
const initialState = {
counter: 0
};
const counterReducer = (state = initialState, action) => {
if(action.type==="INCREASE"){
return {
counter: state.counter+1;
}
}
return state;
};
The question is when this code counter: state.counter+1;
is run will it change counter from 0 to 1 here
const initialState = {
counter: 0
};
What confuses me is that if it changes immutably, what makes it possible that the previous state is remembered if this code is run:
if(action.type==="INCREASE"){
return {
counter: state.counter+1;
}
more than once. Hope you got my point if not pls let me know