I'm doing some React-Redux practice and I've noticed a behaviour I can't understand: it works or not depending on if I use + 1 / - 1 or ++ / -- operators.
This is my reducer:
const counterReducer = (state = { counter: 0 }, action) => {
switch (action.type) {
case "INCREMENT":
return {
counter: state.counter + 1,
};
case "DECREMENT":
return {
counter: state.counter - 1,
};
default:
return state;
}
};
and it works fine.
but if I change the increment and decrement to:
const counterReducer = (state = { counter: 0 }, action) => {
switch (action.type) {
case "INCREMENT":
return {
counter: state.counter++,
};
case "DECREMENT":
return {
counter: state.counter--,
};
default:
return state;
}
};
It will still fire the action without updating the Redux state.