Animated state transitions
Animate content changes caused by a React Transition.
React 19+ · Component
<ViewTransition> opts a component subtree into browser View Transition animations during React Transitions and Suspense updates. It is currently available only in React’s Canary and Experimental channels.
ViewTransition marks a component subtree for browser View Transition animations. React associates the nearest nested DOM node with a transition name, starts the browser transition during supported Transition or Suspense updates, and applies the default cross-fade or configured enter, exit, update, or shared-element classes.
<ViewTransition name="unique-name" enter="enter-class" exit="exit-class" update="update-class" share="share-class">{children}</ViewTransition>| Name | Type | Description |
|---|---|---|
name | string | Optional unique name for the view transition; intended for shared-element transitions. |
enter | string | (() => string) | CSS class or class callback used when the component enters. |
exit | string | (() => string) | CSS class or class callback used when the component exits. |
update | string | (() => string) | CSS class or class callback used when the component updates. |
share | string | (() => string) | CSS class or class callback used for shared-element transitions. |
A React component that renders its children and activates browser View Transition animations for eligible updates.
import { Suspense, ViewTransition, startTransition, useState } from 'react';
export default function App() {
const [show, setShow] = useState(false);
function toggle() {
startTransition(() => setShow(value => !value));
}
return (
<main>
<button onClick={toggle}>Toggle</button>
<ViewTransition>
<Suspense fallback={<p>Loading…</p>}>
{show ? <p>Details are visible.</p> : <p>Details are hidden.</p>}
</Suspense>
</ViewTransition>
</main>
);
}Wraps changing content in ViewTransition and marks the state update as a Transition so React can animate the update.
Animate content changes caused by a React Transition.
Animate a component when it is mounted or removed.
Coordinate matching elements across screens or locations.
Style animations differently according to the transition cause.
SuspenseuseDeferredValuestartTransitionaddTransitionTypeTransition