Skip to content
WunderUI

useInViewAppear

Pro

Plays a chart's appear sequence once, when the chart scrolls into view.

import { useInViewAppear } from "@wunderui/react"

Playground

Weekly sign-ups

state: hidden

Installation

useInViewAppear comes with WunderUI Core and Pro, in the entry of the package from your plan. See the plans. Then import it:

tsx
import { useInViewAppear } from "@wunderui/react"

When to use

Use useInViewAppear for

  • The root of a custom chart that should draw in once, when the person scrolls to it.
  • A chart that shows a skeleton first and should play its sequence when the data arrives, with .
  • Any block styled with the attribute of the WunderUI stylesheet.

Use something else for

  • Line Chart for a finished chart. Its frame, like the sparklines and the status tracker, already uses this hook.
  • Sparkline for small trend charts that draw in by themselves.
  • useChartAnimation for the animation props for a legacy Recharts series. It takes the state of this hook.
  • useLoadSequence for a whole dashboard that should enter in reading order. A chart inside it waits for it by itself.
  • An IntersectionObserver for revealing any other content, lazy loading or counters. This hook only sets the state for the chart styles.

Signature

Attach to the chart root and spread on it. The state stays until a quarter of the root is visible, turns while the sequence plays and after it. A chart that is already on screen at mount plays right away. The styles that react to the attribute ship in the WunderUI stylesheet; the hook only sets the state.

ts
useInViewAppear<T>(animate?: boolean, ready?: boolean, threshold?: number): { ref: React.Dispatch<React.SetStateAction<T | null>>; state: ChartAppearState; }

Parameters

ParameterTypeDefaultDescription
animate optionalbooleantrue plays the sequence. settles on at once. Switching it back to later does not restart a sequence that has been settled; toggle for that.
ready optionalbooleantrueSet while the chart shows its loading skeleton. The state goes back to , and the sequence plays once is again, so the series arrive together with the data.
threshold optionalnumber0.25The share of the root, from 0 to 1, that has to be on screen before the sequence starts. A root that is more than times as tall as the viewport (four screens at the default) can never reach it: lower the value for a very tall chart.

Returns

An object with the for the root and the to put on it.

FieldTypeDescription
refReact.Dispatch<React.SetStateAction<T | null>>A callback ref, not a ref object: pass it to the prop of the chart root. There is no . To use another ref on the same element, call both from one callback.
stateChartAppearState while it waits (the box is transparent and 8 px low), while the sequence runs, after it, when there is no motion: , reduced motion, a background tab or a browser without .

Behavior and motion

The hook decides when the sequence starts; the sequence itself is CSS that keys on `data-chart-appear`.

State
while it waits, for 1.8 seconds while the sequence plays, then . It plays once: later re-renders, resizes and tooltips never replay it. With the state is from the start.
When it starts
In a layout effect, before the first paint. If a quarter of the root (or your ) is on screen already, the sequence starts at once. Otherwise one waits for the root, starts the sequence on the first hit and disconnects. A background tab skips the sequence and shows the chart complete.
Loading
While is the state is again, so a skeleton can show and the series arrive with the sequence once the data does. Inside a dashboard load sequence the hook also waits until the sequence plays, so the chart starts when its card has landed.
Server rendering
Nothing touches or during render, and on the server the layout effect does not run. The server markup says , so the box is transparent until the page hydrates, and the stylesheet shows it at once for people who prefer reduced motion.
Cleanup
The observer is disconnected after the first hit, when the dependencies change and on unmount. The timer that ends the sequence is cleared on unmount.
Motion
The stylesheet rises the box by 8 px while it fades in over with , grows bars from their baseline with a stagger (, 0 to 1) and draws lines along their path. The movement is and ; a line draws by its stroke offset.
Reduced motion
Under the state is at once and the stylesheet shows the chart complete, with no animation. The chart is never transparent for these visitors, not even before hydration.

Best practices

  • Do

    Put and on the same element, the root of the chart. The styles key on that attribute.

  • Do

    Pass when the chart has a loading state, so the sequence plays when the data arrives, not under the skeleton.

  • Don’t

    Do not use it for content that must be visible at once. The root is transparent until the sequence starts, so text people have to read belongs outside of it or in a chart.

  • Do

    Give the root a fixed height. The box rises by a few pixels while it appears, and a root that changes its size makes the page jump.

  • Don’t

    Do not pass an object ref. is a callback; merge it with your own ref in one callback when the element needs both.

  • Don’t

    Do not spread on an element that is not the one with the ref. The hook observes the element that has the ref.

  • Do

    Lower for a chart several screens tall. A quarter of such a root is never on screen at once.

Notes for AI

Give your coding assistant the page or the MCP call instead of screenshots.

MCPget_component("useInViewAppear")
Importimport { useInViewAppear } from "@wunderui/react"

The full library index for assistants is at /llms.txt.