You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b84d873
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/react/Activity.md
+183-7Lines changed: 183 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ Activity is useful when part of the UI may become hidden and visible again. Unli
67
67
68
68
Use an Activity boundary when preserving that work is valuable—for example, for a tab the user is likely to revisit or a panel that can prepare data in the background. A hidden boundary retains its state and DOM nodes, so it continues using memory. If the content is unlikely to become visible again, conditionally rendering it may be preferable because unmounting allows React and the browser to release its resources.
69
69
70
-
### Preserving state while content is hidden {/*restoring-the-state-of-hidden-components*/}
70
+
### Preserving component state while content is hidden {/*restoring-the-state-of-hidden-components*/}
71
71
72
72
When this condition becomes false, React removes `<Sidebar>` from the tree and discards its state:
73
73
@@ -105,7 +105,7 @@ export default function App() {
In this example, filter the video list, open a result, and then go back. The search text and filtered results are preserved because the list remains mounted inside the hidden Activity boundary.
189
+
190
+
<Sandpack>
191
+
192
+
```js
193
+
import { Activity, useState } from'react';
194
+
195
+
constvideos= [
196
+
{
197
+
id:1,
198
+
title:'React Keynote',
199
+
description:'The latest news from the React team.',
200
+
},
201
+
{
202
+
id:2,
203
+
title:'Building with Actions',
204
+
description:'Handle mutations and pending states with Actions.',
205
+
},
206
+
{
207
+
id:3,
208
+
title:'Animating View Transitions',
209
+
description:'Create polished transitions between screens.',
210
+
},
211
+
{
212
+
id:4,
213
+
title:'Understanding Server Components',
214
+
description:'Render components ahead of time on the server.',
The search field is controlled by `VideoList` state. Hiding the list preserves that React state when the user opens a video. The next example shows a different case: state stored by the browser in an uncontrolled field.
348
+
349
+
---
350
+
175
351
### Preserving DOM state while content is hidden {/*restoring-the-dom-of-hidden-components*/}
176
352
177
353
An Activity boundary also preserves state held by the browser in DOM nodes. This includes an uncontrolled input's current value, scroll position, and media playback position.
0 commit comments