-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components Re-rendering #18
Comments
The desired behaviour is not re-rendering on state updates when deep value of selector has not changed. It should work! |
Hmm yeah this is what I thought but I can't see how this can be achieved. Because in the code the const [state, setState] = useState();
sub(setState); So anytime the subscriber fires it is going to cause a re-render. Here is a code sandbox showing this: https://codesandbox.io/s/peaceful-http-lk8bx?file=/src/App.js Shouldn't |
I've opened a PR that I believe fixes this issue. (Sorry for the confusing account switching 😂 Me and JakeNap are the same person). Let me know what you think? I've tested this tweak in the PR and it fixes my issue and I think it's how useSelector should handle state updates. But there maybe some context I'm missing as to why this library doesn't do this already. |
@RichardLindhout any thoughts on this? |
Given the following example my understanding is that
Component
should only re-render whenvalue
changes. But it seems that becauseuseSelector
internally usesuse
which usesuseState
you are essentially subscribing to the entire state update but just returning a filtered value? SoComponent
re-renders whenever anything in state changes? Or have I misunderstood something?The text was updated successfully, but these errors were encountered: