Replies: 4 comments
-
Interesting,
const useStore = store => {
store.getCurrentValue = store.getState
return useSubscription(store)
}
Need to ensure that replacing the synchronous useLayoutEffect with useEffect will not cause unforeseen issues |
Beta Was this translation helpful? Give feedback.
-
useEffect should not cause any problems, i think, but it should be somehow tested, yeah (but how?). |
Beta Was this translation helpful? Give feedback.
-
Seems there is very subtle but measurable difference In case with very frequent updates, some of them able to "seep" between react phases, which leads to rerendering, if that example is correct |
Beta Was this translation helpful? Give feedback.
-
Seems like difference was fixed between react 16.8.6 and current 16.12.0. But despite this, the team already had a new idea, so let them decide what they can offer for us at first. |
Beta Was this translation helpful? Give feedback.
-
Currently, useStore hook subscribes in render phase. That makes it not compatible with future concurrent mode changes.
Proposal
Reimplement useStore with official useSubscription hook provided by react team.
Use case
Avoid subscribing in render phase.
Make it fully compatible with future react changes.
use-subscription package
I made a small codesandbox and it seems that edge case for dispatching in child components before parent subscription works fine.
Event if you don't want to rely on extra dependency, we can use similar techniques to make useStore compatible with concurrent mode.
@zerobias, what do you think?
Beta Was this translation helpful? Give feedback.
All reactions