You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Curious what the reason is for deferring the assignment of valueRef.current into the layout effect callback - why not just assign it unconditionally in Provider()?
Regarding the stale closure - it seems like the useReducer usage here is incorrect - the reducer function passed to useReducer references the enclosed value binding from the first execution of useContextSelector(), since useReducer's reducer reference is considered immutable. A corrected version would be:
It looks like React defers calling the reducer until the component has rendered which we don't i.e. dispatch will queue up that invocation rather than immediately invoke it like we do in Preact. That seems to be the main difference here, this is similar to the explanation in #2750 (comment)
Reproduction
https://codesandbox.io/s/nostalgic-wilson-3vs0s
Steps to reproduce
Click on the "+1" button multiple times.
Expected Behavior
What React does: both counters increment simultaneously.
Actual Behavior
With Preact, the first update is ignored and the "local counter" is offset by one to the "global counter".
Came up in dai-shi/use-context-selector#36
cc @marvinhagemeister @dai-shi
The text was updated successfully, but these errors were encountered: