React Odometer.js is a wrapper component that integrates the Odometer.js library into React applications, providing animated numerical counters. The current stable version is 3.1.3. While it doesn't follow a strict release cadence, updates appear to coincide with significant React API changes or new features, such as the adoption of hooks in v3.0.0 for React 16.8+. Its primary differentiator is simplifying the use of Odometer.js within a React ecosystem, abstracting away direct DOM manipulation typically required by the underlying library. It ships with TypeScript types, enhancing developer experience and type safety. A key aspect of its usage is managing server-side rendering (SSR) environments like Next.js or Gatsby, where dynamic imports are necessary to prevent issues with Odometer.js's reliance on the browser's `document` object.
npm install react-odometerjsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `react-odometerjs` into a React component, updating its value after a delay to show the animation. It also highlights basic styling and essential CSS theme import requirements.
Upgrade your `react` and `react-dom` packages to at least `16.8.0`.
Refactor usage from `<Odometer value={1234} options={{ format: '(.ddd),dd' }} />` to `<Odometer value={1234} format='(.ddd),dd' />`.Remove the `selector` prop; the component now manages its own DOM element selection internally.
Wrap the `react-odometerjs` component import with a dynamic import and `ssr: false` option. Refer to the Next.js or Gatsby integration examples in the documentation for specific implementation details.
Ensure you have installed the `odometer` npm package (`npm install odometer`) and then add a `<link rel="stylesheet" href="odometer-theme-default.css" />` to your `index.html` or import a theme CSS file in your main application entry point (e.g., `import 'odometer/themes/odometer-theme-default.css';`).
For type checking, rely on TypeScript's built-in type inference or import the `OdometerProps` interface; do not expect runtime PropTypes to be present.
Use a dynamic import for the `Odometer` component with `ssr: false`. Example for Next.js: `const Odometer = dynamic(import('react-odometerjs'), { ssr: false, loading: () => 0 });`Pass Odometer options directly as props to the component. Change `<Odometer value={1234} options={{ format: '(.ddd),dd' }} />` to `<Odometer value={1234} format="(.ddd),dd" />`.Ensure that the `odometer` npm package is installed (`npm install odometer`) and a theme CSS file (e.g., `odometer/themes/odometer-theme-default.css`) is properly imported and applied globally or in the component's scope. Also, confirm the `theme` prop, if used, matches the imported CSS.
Update your `react` and `react-dom` packages in your project to version `16.8.0` or higher to support React Hooks.