Implement React's hook update queue: lanes, skipped updates, rebasing and the eager useState bailout

hardAbout 55 minutesUpdated CodingProreactinternalshookslanesconcurrent-renderingusestateusereducer
Not solved

Share this question

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

Stuck? Take a hint

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.

Every question and answer7 days, one payment