react-countup is a React component that provides an easy-to-use wrapper around the CountUp.js library, enabling numerical value animations within React applications. As of version 6.5.3, the library is actively maintained, with frequent patch and minor releases primarily focused on dependency updates, bug fixes, and incorporating new features from the underlying countup.js library, such as `useIndianSeparators` and scroll spy enhancements. It offers both a declarative component API (<CountUp />), a flexible render prop pattern, and a `useCountUp` hook for more fine-grained imperative control over the animation instance. Key differentiators include its robust API for controlling animation duration, delay, decimal and grouping separators, prefixes/suffixes, easing functions, and scroll-triggered animations, abstracting away the direct CountUp.js instance management. It also ships with TypeScript types, enhancing developer experience in typed projects.
npm install react-countupVerified import paths — ran on the pinned version, not inferred.
Demonstrates the primary ways to use react-countup: as a simple component, with a render prop for manual control, and using the `useCountUp` hook for imperative animation management, including handling dynamic `end` values with the `redraw` prop.
Review the GitHub release notes and README for your target major version to identify necessary code adjustments.
Add the `redraw={true}` prop to your `CountUp` component if you intend for the animation to restart upon changes to its `end` prop.If experiencing ESM import issues, verify your build system's module resolution and consider testing updates in a controlled environment to catch unexpected behaviors.
For SSR applications, consider dynamically importing the `CountUp` component or rendering it only on the client-side (e.g., using `typeof window !== 'undefined'` checks or a dedicated `NoSSR` component) to avoid issues.
Ensure `useCountUp` is called directly within the body of a React function component or another custom hook, strictly adhering to React's Rules of Hooks.
Interact with the CountUp instance methods (e.g., `start`, `pauseResume`) only when the component is mounted and the ref is available, often within React's `useEffect` hook or event handlers that trigger after initial render.
To make the animation restart when the `end` prop changes, you must explicitly add the `redraw` prop to the `CountUp` component: `<CountUp end={newValue} redraw />`.