@use-it/auto-counter
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@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

Package Sidebar

Install

npm i @use-it/auto-counter

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

5.26 kB

Total Files

7

Last publish

Collaborators

  • donavon