Question presented to candidate: "A tab panel loses its scroll position and form input every time the user switches away. How would you keep it without keeping it mounted and running?"
What a strong answer should cover:
<Activity mode="hidden">hides a subtree while preserving its state. React keeps the component's state and DOM but unmounts its effects.- That is the key distinction and the whole reason it exists: state survives, effects do not. Timers stop, subscriptions unsubscribe, observers disconnect — but the input value, scroll position and local state are all still there when it returns.
- The alternatives are both worse: a conditional unmount destroys state, and CSS
display: nonekeeps everything running — timers, subscriptions, polling. - Returning to
mode="visible"restores the state and re-runs the effects, exactly like a remount for effect purposes. - Because effects tear down and set up again, this only works if your effects are idempotent — the same property
StrictModetests for. - React can also use hidden Activity boundaries to pre-render content at low priority, so it is ready before the user asks for it.
- Typical uses: tab panels, multi-step wizards, a route the user is likely to go back to, an off-screen detail pane.
Clarifying questions expected:
- "Should the hidden panel keep polling, or stop?" — Activity stops it;
display: nonedoes not. - "How much state is there to lose?" — a single scroll position may not justify it.
Code / implementation expected: Optional. The three-way comparison against a conditional and display: none is what makes it land.