This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
feat(context-selector): add initial implementation #2292
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aacbb24
to
0bffe63
Compare
Perf comparison
Perf tests with no regressions
Generated by 🚫 dangerJS |
…b.com/stardust-ui/react into feat/context-selectors
layershifter
commented
Feb 12, 2020
|
||
## Usage | ||
|
||
TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops
miroslavstastny
approved these changes
Feb 12, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds initial implementation of
useContextSelector()
anduseContextSelectors()
hooks.What it solves?
Current API features shorthand collections:
What is wrong with shorthand collections?
👎 it's too complicated to compose components and perform changes in React tree
However, we need to propagate props somehow and React Context is only right thing. We cannot use
React.Children
as it will break on any wrapped element. But, React Context by default notifies all its consumers even if changed data are not relevant for that consumer 💣 And it cant' be solved by multiple React contexts:How it works?
calculateChangedBits
Why two hooks?
Each
useContextSelector()
creates uses 3 hooks (useState()
,useRef()
) to represent its state and it's obviously bad for performance to use it to get 10 properties as it will create 30 hooks.useContextSelectors()
will execute multiple selectors and will use only 3 hooks.For PoC please check #2207 which contains changes in
List
component.