-
Notifications
You must be signed in to change notification settings - Fork 58
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
How does selector memoization work? #81
Comments
As far as I understand, the RFC says if the selector is memoized like const count1 = useContextSelector(context, useCallback(v => v[0].count1, [])); It skips re-evaluation. But, if not const count1 = useContextSelector(context, v => v[0].count1); It will re-evaluate. So, it's just about optimization of re-evaluation of the selector function. This library doesn't include such optimization, assuming the selector function is fairly lightweight.
It will use the latest values, so it behaves correctly. Is it clear? I'm afraid I don't get the point of your question. |
Thank you for your explanation. In that case, I think there is a bug in the Right now, the
I think those steps will produce incorrect results. |
Sorry for code readability, but that's not a dependency array. It's an initial value for |
I see. Thank you for the clarification. |
The RFC proposes that both the context and the selector are memoized.
However, it seems like this library works differently. E.g.:
From my understanding of the RFC, this should defeat the memorization and make
useContextSelector
ineffective as a performance optimization.Obviously, the above snippet works for this library, so could you please explain how? Is the selector memoized, and if so, how?
To cite a more complex example, let's look at this snippet:
How will this behave if both
Context
andid
may change? (If props are too constant, thenid
may also be state.)The text was updated successfully, but these errors were encountered: