implementation with useContextSelector (Experimental) ⚠️ #1350
This PR implements the connect api for and hooks apis using a proposed RFC: Context Selectors
This is not an official React API
The point of this PR is to illustrate how libraries can shrink and become less complicated with this proposed API change. Please note not all tests pass because not all tests are relevant. It's possible there are edge case bugs too, this PR is for exploration and illustration, not for merging.
How to use
get a working copy of react with useContextSelector
checkout this react-redux branch
You can see a built version of both the react and react-redux lib here: https://codesandbox.io/s/react-redux-context-selector-truop
master: around 5.69kb
these sizes should be smaller in real bundles if dependency deduping is working correctly. this means that relative decrease in size should be magnified
Deploy preview for react-redux-docs ready!
Built with commit bfaef05
Thanks, I'll try to look at it later.
The immediate observation I'd make is that from a project management standpoint, this would effectively require another major, because:
Definitely would require a new major, no question there.
as for tearing, that's an interesting problem. Unfortunately I don't think there is a way for concurrent react support to exist and still have tearing support. On the flip side maybe when concurrent react is mature there will be a way to lean into it. Imagine yielding the render once a dispatch occurred so you could restart it with the updated state value. It would still be possible to get yourself into trouble but that true today too :)
The SSR bit is interesting, are you saying that because you need to synchronously render everything, mounted based dispatches need to be visible to children b/c there is no opportunity to wait for a second render to resolve things?