Does anyone know if react-redux will trigger re-render in case reducer returns unchanged state
export default const reducer = (state, action) => state;
(Sorry, traveling with the phone and too uncomfortable to check myself)
Does anyone know if react-redux will trigger re-render in case reducer returns unchanged state
export default const reducer = (state, action) => state;
(Sorry, traveling with the phone and too uncomfortable to check myself)
Basic workflow of using React Redux.
Find more on this Redux example.
@KrunalLathiya, do you think this answered my question? Or you don’t care and just promoting your article?
Answering my own question and also for those who might be wondering: NO, the connect
wrapper will not trigger re-rendering in general. There is a catch, as it will compare previous and incoming states by reference and not by value, so any of these will trigger false re-render:
return [...state, ...sameDataFromFetchThatIAlreadyHave];
return [...state, ...[]];
return [...state];
Why I was bothering in the first place? I wanted to know if I can use redux
not only as centralized state manager, but also as centralized action manager where I’ll have special reducer
that will do all sorts of side-effects with DOM
events that do not cause the change of app’s state. And it turns out, it’s possible and it opens doors for much cleaner code and patterns: useDispatch()
will be the only gateway between view and business logic - kinda neat!