-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Multiple state hooks in a component #3645
Conversation
Size Change: +180 B (0%) Total Size: 43.7 kB
ℹ️ View Unchanged
|
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.
As already mentioned in slack: Really impressed with your debugging skills on this one! This is great 💯
// we bail out of updating. | ||
// Thinking: would this be dangerous with a batch of updates where | ||
// Comp1 updates --> Comp2 updated in same batch twice but has same eventual state --> this leads to us | ||
// not diving into Comp3 |
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.
Right now I can't come up with a scenario where that would break. We're already somewhat in edge case territory here with components being re-scheduled as part of the same commit. So I'd say let's keep on eye on that, but I don't expect there to be issues.
// have values that aren't equal to one another this pushes | ||
// us to update further down the tree | ||
const shouldSkipUpdating = stateHooks.every(hookItem => { | ||
if (!hookItem._nextValue) return true; |
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.
Per Marvin's comment above, shouldn't this check for _nextValue
being undefined?
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.
_nextValue in this case is an array like the normal state hook containing [value, updater] so using ! is the least bytes and correct as it's array or undefined
Currently the last sCU wins which basically means we are losing a bit of granularity, as well as filtering out React.memo when wrapped. The new flow looks like the following: