useChartAnimation
Legacy: the draw-in animation props for Recharts series, used by the legacy Recharts charts the templates still use.
import { useChartAnimation } from "@wunderui/react"Legacy: used by the legacy Recharts charts that the templates still use. The charts of @wunderui/react/charts draw in on their own; for your own chart card see useChartReload · useGlide · useAnimatedNumber
Playground
Installation
useChartAnimation comes with WunderUI Core and Pro, in the entry of the package from your plan. See the plans. Then import it:
import { useChartAnimation } from "@wunderui/react"When to use
Use useChartAnimation for
- A custom chart built from Recharts parts (, , ) that should draw in once and then stay still, like the legacy charts of the package.
- A table or list with many small Recharts charts, where keeps the page calm.
- A Recharts chart that appears with : pass its state so the draw-in runs exactly while the appear sequence does.
Use something else for
- Line Chart for a finished chart. The charts of draw in on their own and need no hook.
- useInViewAppear for the appear sequence itself: waiting for the chart to scroll into view and fading the box in. This hook only switches the draw-in of the series on and off.
- useChartReload for the reload of a chart card: loading skeleton, your task, then the chart draws again.
- useGlide for hover marks that move between points. They glide by a CSS transform, not by the Recharts animation.
Signature
Returns , , and for a Recharts series. The series draw in once on mount and then stop animating, so a resize or new data does not replay the draw-in. Under reduced motion they never animate.
useChartAnimation(animate?: boolean, appear?: ChartAppearState | undefined): { isAnimationActive: boolean; animationDuration: number; animationEasing: "ease-out"; animationBegin: number; }Parameters
Returns
The four animation props of a Recharts series. Spread them on every series of the chart (, , ) with .
Behavior and motion
The hook is one flag with a timer. Recharts does the drawing; the hook decides whether it may.
- State
- The flag starts as and no reduced motion. Without , a timer of 1.2 s (the duration of 1.1 s plus 100 ms) switches it to while the chart is on screen, so a resize or new data afterwards does not replay the draw-in. When changes later, the flag is set again to the new value (and not under reduced motion), which is how a chart that leaves its loading skeleton draws in then. With there is no flag state of its own: the value is .
- Server rendering
- The preference for reduced motion is read once, in the first render, with . On the server there is no , so the returned flag can differ between server and client for a visitor who prefers reduced motion. The legacy charts mount their series on the client only (after the container has measured itself, or when the appear state leaves ), so nothing mismatches there. In your own chart, mount the series the same way and do not print the flag into server markup.
- Cleanup
- The timer is cleared when the component unmounts, when the flag has already turned , and when is given.
- Motion
- Recharts draws the series with 1100 ms, and no delay. These are plain numbers and a keyword for the Recharts props; they are not WunderUI motion tokens, which is one reason the new chart system draws with its own CSS.
- Reduced motion
- Under the flag is from the first render and the timer never starts. The preference is read once when the component mounts; switching it while the chart is on screen takes effect on the next mount.
Best practices
- Do
Spread the whole object on every series of the chart. The four props belong together and a series without them draws with the Recharts default.
- Do
Call the hook once per chart, in the component that renders the series, and hand the same object to every , or .
- Do
Pass for lists and tables of small charts, and for charts that update often.
- Do
With , pass its as the second argument and mount the series only when the state is not , as the legacy charts do.
- Don’t
Do not use it for the charts of . They draw in on their own and do not read this hook.
- Don’t
Do not print into server-rendered markup. It reads the reduced-motion preference in the first render and can differ between server and client.
- Don’t
Do not rely on the draw-in to show data. It is decoration: the chart needs a label, a description or a table for people who do not see it.
Notes for AI
Give your coding assistant the page or the MCP call instead of screenshots.
get_component("useChartAnimation")import { useChartAnimation } from "@wunderui/react"The full library index for assistants is at /llms.txt.