I noticed that if I dispatch an action that happens to not to modify the state, the component is re-rendered anyway.
Example:
// for simplicity sake, we simply pass state on (no mutation)
const someReducer = (state, action) => state
const App = () => {
const [state, dispatch] = useReducer(someReducer, 0)
// in my use case, I want to dispatch an action if some specific condition in state occurs
if(state === 0) {
dispatch({ type: 'SOME ACTION' }) // type doesn't matter
}
// return some JSX
}
I get:
Error in app.js (16929:26)
Too many re-renders. React limits the number of renders to prevent an infinite loop.
Is this by design? Should it be this way?