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
Tidy up React Scope API #19352
Tidy up React Scope API #19352
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 86fd780:
|
Details of bundled changes.Comparing: 147179a...86fd780 react-is
Size changes (experimental) |
Details of bundled changes.Comparing: 147179a...86fd780 react-is
Size changes (stable) |
I'm not quite following. Wasn't the idea that you declare separate Scope per piece of functionality, similar to Context? How can you be sure of the type of the exposed scope's refs after this change? Presumably any traversal will now "see" unrelated Scopes, unless I'm missing something. |
That's how scopes used to work. They changed a while ago and lost their traversal methods entirely, instead opting to use React Context to traverse up and a method to find child React Context in a sub-tree. This was one of the stems of work we had last year when Sebastian was in London, around making Scopes API "safter" and less super-powered. |
This PR changes the React Scopes (experimental) API, so it's simpler. Previously, you used Scopes like this:
With this PR:
So they work like
Fragment
or other common React exports, and can be used directly as the element type.The reason we have
unstable_createScope
was because in the older design of the Scopes API,createScope
used to take an argument. That specific feature was removed ages ago, so it actually makes no sense to have to docreateScope
each time.