react-hook-timeout

1.0.0 • Public • Published

react-hook-timeout

A component of React Hook based on setTimeout and clearTimeout that supports multi-timeout management.

Install

Using npm

npm install react-hook-timeout --save-dev

Usage

ESM usage

import useTimeout from 'react-hook-timeout';

export default function myComponent() {
    const { setTimeout } = useTimeout();
    setTimeout(() => {
        //delay doing something after 5 seconds
    }, 5000);
}

Description

This hook component supports to remove all timeout automatically when component uninstalled.

Method

setTimeout(callback, delay)

  • callback => {Function} The callback function for the timeout response.(required)
  • delay => {Number} Delay time.(required)
  • return value => {Number} Timeout ID

clearTimeout(id)

  • id => {Number} Timeout ID.(required)

License

react-hook-timeout is MIT licensed.

Package Sidebar

Install

npm i react-hook-timeout

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

7.26 kB

Total Files

7

Last publish

Collaborators

  • amoydreamer