Animate transitions with version-gated ViewTransition
Distinguish update priority from animation
React 19.3 made ViewTransition a stable React DOM feature, according to the September 9, 2026 release announcement. It was experimental before that version; do not import it into ordinary React 18, 19.0, 19.1 or 19.2 apps. Use a reviewed patched matching React/React DOM 19.3+ version and a browser with compatible View Transition support. A React transition concerns update priority; a view transition animates a visual change. Neither is required for basic correctness.
import React,{useState,startTransition,ViewTransition} from 'react';export default function App(){const [open,setOpen]=useState(false); return <section><button aria-expanded={open} aria-controls="sample-detail" onClick={()=>startTransition(()=>setOpen(v=>!v))}>{open?'Hide':'Show'} sample details</button><div id="sample-detail">{open&&<ViewTransition><p>Cedar sample: collected for a synthetic exhibit.</p></ViewTransition>}</div></section>;}The detail appears or disappears and the disclosure button remains in place. In a compatible browser the inserted or removed boundary may animate. The enter and exit cases differ from updates inside a retained boundary and shared-element animations between matched names. Ordinary urgent changes should not be delayed simply to get an animation. React coordinates the browser API for this boundary; do not also start a manual browser view transition around the same update.
Preserve meaning with no animation
import React,{useState,useTransition,startTransition,useDeferredValue,memo,Profiler} from 'react';export default function App(){const [open,setOpen]=useState(false); return <section><button aria-expanded={open} aria-controls="sample-detail" onClick={()=>setOpen(v=>!v)}>{open?'Hide':'Show'} sample details</button><div id="sample-detail">{open&&<p>Cedar sample: collected for a synthetic exhibit.</p>}</div></section>;}This fallback uses ordinary state and has the same content and keyboard interaction. Select a compatible source entry at build time; a static named import of a missing export cannot be repaired with a runtime browser check. Test reduced motion, browser support, focus and final content independently. Motion must not carry information that is otherwise unavailable.
Respect motion preferences and bound navigation
import React,{useState,startTransition,ViewTransition} from 'react';const labels=['Cedar sample','Birch sample'];export default function App(){const [index,setIndex]=useState(0);const [allow,setAllow]=useState(false); function move(delta){const update=()=>setIndex(i=>Math.max(0,Math.min(labels.length-1,i+delta)));if(allow&&!window.matchMedia('(prefers-reduced-motion: reduce)').matches&&typeof document.startViewTransition==='function')startTransition(update);else update();} return <section><label><input type="checkbox" checked={allow} onChange={e=>setAllow(e.target.checked)}/> Allow motion</label><button disabled={index===0} onClick={()=>move(-1)}>Previous</button><button disabled={index===labels.length-1} onClick={()=>move(1)}>Next</button><ViewTransition><p role="status">{labels[index]}</p></ViewTransition></section>;}Motion is off by default. Previous is disabled on Cedar, Next on Birch. The event handler checks the current browser preference and capability before requesting an animated update; otherwise the state changes urgently. This is a client-only 19.3+ example; the older source above is a distinct compatibility lane. Browser animation timing and screen-reader announcements require actual testing. Practice: check both ends of the catalogue, enable motion, then simulate reduced motion and verify that the same content remains available.