react-use-counter

0.0.0 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i react-use-counter

Weekly Downloads

1

Version

0.0.0

License

MIT

Unpacked Size

5.27 kB

Total Files

4

Last publish

Collaborators

  • bsonntag