@use-it/auto-counter

A custom React Hook that auto-increments a value.

Usage no npm install needed!

<script type="module">
  import useItAutoCounter from 'https://cdn.skypack.dev/@use-it/auto-counter';
</script>

README

@use-it/auto-counter

A custom React Hook that auto-increments a value every delay msecs.

npm version

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