Hiding and restoring with <Activity>
Conditional rendering throws a subtree away. Unmount it and its state is gone; come back and you start from scratch. That is often not what you want for tabs, modals, or back-and-forward navigation, where someone expects to find the screen as they left it.
React's <Activity> component renders a subtree you can hide and show:
<Activity mode={visible ? 'visible' : 'hidden'}>
<Panel />
</Activity>
While the mode is "hidden", React hides the subtree's DOM and cleans up its
effects — timers stop, subscriptions detach — but it keeps the state. Toggle
the mode back to "visible" and the component reappears with the values it
held, and its effects run again.
Pass mode a value to control it (you will usually derive it from state), or
switch between "visible" and "hidden" directly. Because hidden content is not
in the accessibility tree, screen readers ignore it until you show it again.
You get the work and DOM of an unmounted screen, but the state of a mounted one.
Your job is to hide a stateful panel and restore it.
Challenge
A panel you hide should come back exactly as you left it, state and all. Export
an App component from App.jsx with a Toggle button and a Counter button
that increments a count. Wrap the counter in an <Activity> whose mode moves
between "visible" and "hidden" when Toggle is clicked.
The Test increments the counter, hides it, expects it to leave the accessibility
tree, then shows it again and expects Count: 1, its state preserved. The
starter never hides or increments, so the Test fails.