Skip to content
HooksPro

useInViewAppear

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

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.

See alsoArea Chart

Import

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

Comes with WunderUI Core and Pro, in the package from your plan. See the plans.

Signature

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

Parameters

ParameterTypeDefault
animate?booleantrue
ready?booleantrue
threshold?number0.25

Returns

FieldType
refReact.Dispatch<React.SetStateAction<T | null>>
stateChartAppearState

Examples

A custom chart root

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

export function RevenueChart({ data, loading }: { data: Point[]; loading: boolean }) {
  const { ref, state } = useInViewAppear<HTMLDivElement>(true, !loading)
  const animation = useChartAnimation(true, state)
  return (
    <div ref={ref} data-chart-appear={state} className="h-48">
      {/* Recharts series receive {...animation} */}
    </div>
  )
}

Notes

  • means no motion: , reduced motion, a background tab or a browser without IntersectionObserver.
  • (the chart shows its loading skeleton) resets it, so the series arrive with the motion once the data does.
  • The styles for ship in the WunderUI stylesheet; the hook only sets the state.