Dispatch triggered outside React causes N re-renders when useStoreon is used N times
See original GitHub issueHi,
I have an App
component which uses hook A, which calls to hook B.
Both hooks are using useStoreon
hook to get the same value (let’s call it items
) from state.
Both hooks are simple functions without any other hooks involved.
When my component is rendered, hook A gets called, then hook B and console.log
I put inside component prints once.
Everything is fine.
Now I create a function, which changes items
in Storeon store and call that function from component outside StoreonContext.Provider
wrapping App
.
Every time I call that function, component’s console.log
executed 2 times, indicating 2 re-renders instead of one.
I’ve noticed that if useStoreon
hook is used N times, component re-renders N times.
CodeSandbox illustrating the issue: https://codesandbox.io/s/storeon-issue-n-renders-lgoxw
The same CodeSandbox, adapted to use Redux works fine: https://codesandbox.io/s/storeon-issue-n-renders-redux-ilhej
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (9 by maintainers)
Maybe we can ask React and Preact team for this API?
I am working on a new state manager https://github.com/logux/state