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
This constraint prevents subtle bugs where too much or too little animates.
469
+
459
470
</Pitfall>
460
471
461
472
---
462
473
474
+
### Animating enter/exit with Activity {/*animating-enter-exit-with-activity*/}
475
+
476
+
If you want to animate a component in and out while preserving its state, or pre-rendering content for an animation, you can use [`<Activity>`](/reference/react/Activity). When a `<ViewTransition>` inside an `<Activity>` becomes visible, the `enter` animation activates. When it becomes hidden, the `exit` animation activates:
477
+
478
+
```js
479
+
<Activity mode={isVisible ?'visible':'hidden'}>
480
+
<ViewTransition enter="auto" exit="auto">
481
+
<Counter />
482
+
</ViewTransition>
483
+
</Activity>
484
+
485
+
```
486
+
487
+
In this example, `Counter` has a counter with internal state. Try incrementing the counter, hiding it, then showing it again. The counter's value is preserved while the sidebar animates in and out:
Without `<Activity>`, the counter would reset to `0` every time the sidebar reappears.
589
+
590
+
---
591
+
463
592
### Animating a shared element {/*animating-a-shared-element*/}
464
593
465
594
Normally, we don't recommend assigning a name to a `<ViewTransition>` and instead let React assign it an automatic name. The reason you might want to assign a name is to animate between completely different components when one tree unmounts and another tree mounts at the same time, to preserve continuity.
0 commit comments