rslabdocs

Animated Counter

A number that smoothly counts up or down to a new target every time the value changes, no per-frame re-render.

ReanimatedSource

Prerequisites

Just Reanimated; expo install pins the version that matches your SDK.


npx expo install react-native-reanimated

Install


npx @rslab/cli add animated-counter

Usage

import { AnimatedCounter } from '@/components/ui/AnimatedCounter';

<AnimatedCounter
  value={followers}

  className="text-4xl font-bold text-neutral-900 dark:text-neutral-50"
/>;

Pass a custom formatter for currency, percentages, or any other display format:

<AnimatedCounter
  value={balance}

  duration={1200}

  formatter={(n) => `$${Math.round(n).toLocaleString()}`}

  className="text-3xl font-bold text-neutral-900 dark:text-neutral-50"
/>

Props

PropTypeDefault
value
number
-

The target number to count to. Animates from the previous value whenever it changes.

duration?
number
800

Animation length in ms.

formatter?
(n: number) => string
Math.round(n).toLocaleString()

Formats the number on every tick, e.g. for currency or percentages.

className?
string
-

Applied to the underlying Text. Font size, weight, and color are entirely your choice, nothing is hardcoded.

See exactly how this works with an RSLAB subscription.

Get Pro

On this page