React custom hook for odometer (Smoothly transitions numbers with ease).
npm install use-odometerA React custom hook for an awesome library odometer, you can use it to make your react counting app easily.
``bash`
$ yarn add use-odometer odometer
Remember to install peerDependency odometer.
`jsx`
const App = () => {
const [count, setCount] = React.useState(0);
const targetRef = React.useRef(null);
// The ref you want to attach
useOdometer(targetRef, count);
return (
);
};
In my source code, I use default theme stylesheet, you don't need to import again.
But, if you want to use other themes (like car/digital...etc), you need to explicitly import .
eg.
`jsx``
// in your components
import 'odometer/themes/odometer-theme-car.css';
//...
//...
const od = useOdometer(targetRef, value, {
theme: 'car'
});
//...
//.. the same code
---
LICENSE MIT © 2019 realdennis