Quiz - The render model
A <UserCard user={user} /> re-renders on every keystroke in a search box that lives in the same parent, even though the user object never changes. What actually caused the card to re-run?
user prop is a passenger, not the cause.user prop changed identity, and a prop change is one of the triggers that makes a child re-render.You render a reorderable list of rows, each containing an uncontrolled <input>. With key={i} (the array index), a user types into the first row and then sorts the list. What happens?
key={i} pins identity to the slot, not the item — it does exactly what position-matching already did, so the input’s DOM node stays in slot 0 while the label around it is repatched to a different item. The text desyncs onto the wrong row. key={item.id} is what makes identity travel with the data so React moves the DOM node along with it.The React Compiler reads a component and finds it mutates a prop during render. What does it do, and how would you notice?
Inside a render where count === 0, a click handler runs setCount(count + 1) three times in a row. After one click, the counter shows 1. You want it to add 3. What’s the fix and why does it work?
setCount((c) => c + 1) — each updater receives the running queued value (0 → 1 → 2 → 3) instead of re-reading the frozen snapshot.flushSync so each one commits and the next reads the updated count.setCount(count + 3) once — three setter calls on the same snapshot can only ever land on one value.count is frozen at 0 for the whole render, so all three setCount(count + 1) calls are setCount(1) and collapse to one. The updater form reads the value the queue has computed so far rather than the snapshot, so three of them thread 0 → 1 → 2 → 3. setCount(count + 3) happens to give 3 here but doesn’t generalize to async or stacked updates, and flushSync is a batching opt-out for measuring the DOM, not the tool for sequential updates.A master-detail screen renders <UserForm user={selectedUser} />, and the form seeds its fields from props with useState(user.email). Switching the selected user leaks the previous user’s unsaved edits onto the next record. A teammate proposes a useEffect that copies the new props into state on user.id change. What’s the senior call?
<UserForm key={user.id} … /> — changing the key remounts the form, so it’s reborn from the new prop, resetting every field at once with no per-field bookkeeping.key reset is declarative, resets all fields for free, and can never go stale because there’s no copy to keep in sync. Seeding state from props isn’t the bug — it’s exactly what makes the keyed version come up pre-filled with the right record.A native shortcut listener is registered with document.addEventListener('click', …), and a button deep in the React tree calls e.stopPropagation() in its onClick. On React 17+, does the document listener fire when the button is clicked?
stopPropagation contains the event before it can bubble up to document.stopPropagation inside a React handler can only silence other React handlers, never a native document listener.document has already received the event, so it can’t be un-fired.document. A React child’s stopPropagation halts the native event at that root, so it never reaches an ancestor listener on document. The two “yes” answers describe the pre-17 model, when React listened at document itself and couldn’t un-fire an event it had already delivered — a note that outlived the behavior it described.Quiz complete
Score by topic