How to Animate a React App UI with Rive States
Rive animations in React work best when React owns the state and Rive only reflects it. Bind the state machine’s boolean inputs to component props, let the Rive file handle the motion, and never put layout logic inside the animation. Files stay small and the component stays predictable.
What does the React integration actually look like?
The @rive-app/react-canvas package wraps the runtime in a hook. You give it a source, a state machine name, and you get back a component and a controls object.
The core pattern: call useRive, grab the inputs array, and use useEffect to push your React state into those inputs whenever it changes. One direction only — React to Rive.
const { rive, RiveComponent } = useRive({ src, stateMachines: 'AppState' })
useEffect(() => {
if (!rive) return
const input = rive.stateMachineInputs('AppState')?.find(i => i.name === 'isLoading')
if (input) input.value = loading
}, [loading, rive])
Why does my animation reset on every render?
Three usual causes. The src string is rebuilt on each render, so the hook reloads the file. The stateMachines option is a new array instance each time and triggers a reload. Or the component is being remounted because its parent keys changed.
Fix the first two by hoisting constants outside the component. Fix the third by checking the key prop on the ancestor.
A reload looks like a stutter and is easy to misdiagnose as a performance issue. Check the network tab for repeated .riv requests first.
How do you handle multiple Rive files on one page?
Load shared assets once and reuse artboards. If each card on a list has its own animation, one .riv with several artboards loads once and each card requests an artboard name — far cheaper than one file per card.
For lists over about 30 items, virtualize. Canvas rendering costs CPU per visible instance, and 200 live Rive canvases will drop frames on mid-range laptops.
Also consider whether the animation needs to run off-screen at all. Pausing state machines for items outside the viewport is a one-line observer and saves measurable battery.
Which rendering backend should you pick?
| Backend | Good for | Cost |
|---|---|---|
Canvas (react-canvas) |
Most UI animation | Higher CPU, universal support |
WebGL (react-webgl) |
Many instances, shader effects | GPU dependent, larger bundle |
Skia (react-skia) |
Sharp vector detail at scale | Extra ~500 KB wasm |
Canvas is the safe default. WebGL pays off past roughly 20 simultaneous animations. Skia is for interactive illustrations where crispness at any zoom is the product.
How do you keep accessibility intact?
Rive renders into a canvas, which assistive tech sees as a single opaque element. A button built this way is invisible to a screen reader.
Wrap it: put a real button element over the canvas with the accessible label, and let the Rive canvas be purely decorative (aria-hidden set to true). Keyboard focus, tab order, and screen reader announcements all work through the hidden-but-focusable button.
Also respect prefers-reduced-motion. Rive does not do it for you. Check the media query and either skip autoplay or switch to a simpler state.
What does this pattern cost in practice?
A typical UI animation file is 30-100 KB. The React canvas package adds roughly 60-80 KB gzipped to the bundle. That is comparable to a code font and far less than a motion library with its own timeline engine.
The real cost is coordination: the designer must expose inputs with stable names, and the developer must not rename them. Agree on the input contract before build, not after.
Who is this for?
- Teams with a designer who wants to own motion end-to-end.
- Apps where micro-interaction quality is part of the product.
- Games and tools built in React where CSS is not expressive enough.
Not for: marketing pages with a handful of CSS transitions, or teams without design ownership over animation — the file becomes an unmaintainable binary dependency.
Quick Summary
- Bind React state into Rive state machine inputs; never do it the other way around.
- The animation resetting usually means a new
srcorstateMachinesinstance per render. - Canvas is the default renderer; WebGL pays off past about 20 simultaneous animations.
- Overlay a real button element for accessibility — canvas content is invisible to screen readers.
- Budget 30-100 KB per file and team agreement on input names.
Feature list, supported runtimes, and licence tiers are on the Rive tool page.
