0.1.1 • Published 5 years ago

@use-it/auto-counter v0.1.1

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

@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.

ParameterDescription
initialCountAn initial value for the count. Default = 0.
delayA 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