0.0.0 • Published 5 years ago

react-use-counter v0.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

react-use-counter

CircleCI Coverage Status

React hook for counter state.

Installation

Using npm:

$ npm install --save react-use-counter

Using yarn:

$ yarn add react-use-counter

Since this module uses React Hooks you'll need to install at least the 16.8.0 version of react and react-dom:

$ yarn add react@^16.8.0 react-dom@^16.8.0

Usage

import React from 'react';
import useCounter from 'react-use-counter';

function Example() {
  const [count, increment] = useCounter(0);

  return (
    <div>
      You clicked {{count}} times.

      <button onClick={increment}>Click me!</button>
    </div>
  );
}

API

useCounter(initialCount?: number): [number, () => void]

Receives an optional initial count and returns a tuple with the current count and a function to increment the counter.

Contributing

Please feel free to submit any issues or pull requests.

License

MIT