@use-it/auto-counter
v0.1.1
Published
A custom React Hook that auto-increments a value.
Downloads
2
Maintainers
Readme
@use-it/auto-counter
A custom React Hook that auto-increments a value every delay
msecs.
Installation
$ npm i @use-it/auto-counter
or
$ yarn add @use-it/auto-counter
Usage
Here is a basic setup.
const count = useInterval(initialCount, delay);
Parameters
Here are the parameters that you can use.
| Parameter | Description |
| :--------- | :------------------------------------------------------------------------------- |
| initialCount
| An initial value for the count. Default = 0. |
| delay
| A number representing the delay in msecs. Default = 1000 (i.e. 1 second). |
Return
This hook returns the current count.
Example
Let's look at some sample code. Here is a Counter
component that counts up every second.
import React, { useState } from 'react';
import useInterval from '@use-it/auto-counter';
const Counter = () => {
const count = useAutoCounter();
return <h1>{count}</h1>;
};
export default Counter;
License
MIT Licensed