nori-ui

useAnimatedNumber

Animate a numeric value over time. Web uses CSS transitions; native uses Reanimated worklets.

View as JSON

Drives a numeric value smoothly between targets — used internally by Slider, Progress, Toggle, and animated counters. Cross-platform: on web it bridges to a CSS-driven number; on native it bridges to a Reanimated SharedValue.

Usage

import { useAnimatedNumber } from '@nori-ui/core/client';
 
function CountUp({ to }: { to: number }) {
    const value = useAnimatedNumber(to, { duration: 400 });
    return <span>{Math.round(value)}</span>;
}

API

Arguments

NameTypeDefaultDescription
targetnumberThe target value. The hook animates from the previous render's value to this.
options.durationnumber200Animation duration in ms.
options.easing(t: number) => number(t) => tEasing function applied to the normalized 0..1 progress.

Returns

A number — the current interpolated value as of the last animation tick. Re-renders at frame rate while the animation is in flight; stops re-rendering once it settles.

Notes

  • The hook runs on the JS thread on web (requestAnimationFrame) and on the UI thread on native (Reanimated worklet) — both stay 60fps for typical UI animations.
  • Pass a stable easing reference (memoized or module-scoped) — passing a fresh function each render restarts the animation.
  • For multi-property animations, run multiple useAnimatedNumber calls in parallel; the hook is intentionally single-value.
  • Theming — animation token presets (duration.fast, duration.normal, easing.standard).

On this page

Preview theme