use-odometer

0.0.4 • Public • Published

use-odometer

Build Status Coverage Status

A React custom hook for an awesome library odometer, you can use it to make your react counting app easily.

Installation

$ yarn add use-odometer odometer

Remember to install peerDependency odometer.

Usage

const App = () => {
  const [count, setCount] = React.useState(0);
  const targetRef = React.useRef(null);
  // The ref you want to attach
  useOdometer(targetRef, count);
  return (
    <div className="App">
      <p className="target" ref={targetRef} />
      <button onClick={() => setCount(9999)}>
        {/* Just change the number state */}
        Update value
      </button>
    </div>
  );
};

More

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.

// in your components
import 'odometer/themes/odometer-theme-car.css';
//...
//...
const od = useOdometer(targetRef, value, {
  theme: 'car'
});
//...
//.. the same code

LICENSE MIT © 2019 realdennis

Package Sidebar

Install

npm i use-odometer

Weekly Downloads

11

Version

0.0.4

License

MIT

Unpacked Size

6.52 kB

Total Files

12

Last publish

Collaborators

  • realdennis