Implement React's hook update queue: lanes, skipped updates, rebasing and the eager useState bailout
Problem
With concurrent rendering, React can render an urgent update (a click) before an older, slower one (a transition), and the final state must still be what you would get by applying every update in the order it was dispatched. The trick lives in each hook's update queue: React skips low-priority updates, remembers where it skipped, and replays the rest later. Build a model of that queue in plain JavaScript.
const Lane = Object.freeze({ None: 0, Sync: 1, InputContinuous: 2, Default: 4, Transition: 8, Idle: 16 });Ref. UR-1441 · © UIRound · uiround.com/questions/implement-reacts-hook-update-queue-lanes-skipped-updates-rebasing-and-the-eager-usestate-bailout
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 2
- code listings
- 5
- edge cases
- 5
- follow-up questions
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1A render at some lanes processes only the updates whose lane is in that set. What must happen to the updates it skips, and to the ones after them, so the final state is the same as processing everything in order?
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.