@reacthooks.org/use-set-timeout

1.0.8 • Public • Published

Install

$ npm install @reacthooks.org/use-set-timeout

useSetTimeout

A React Hook (using useEffect) which uses window.setTimeout().

Synopsis

In your React component:

import { useState } from 'react'
import useSetTimeout from "use-set-timeout"

function SetTimeout() {
  const [ triggered, setTriggered ] = useState(false)

  useSetTimeout(() => { setTriggered(true) }, 5 * 1000)

  return <p>triggered = { triggered }</p>
}

There is no need to keep a reference to the timeout ID since it will be automatically cleared when the component unmounts.

Please note that the timeout is cleared and reset if you change the timeout ms but not if you change the function fn.

Usage

useSetTimeout(fn, delay)
  • fn is a function to execute
  • delay is the delay in milliseconds

Other Hooks

Please see all of the other reacthooks.org hooks:

Author

$ npx chilts

   ╒════════════════════════════════════════════════════╕
   │                                                    │
   │   Andrew Chilton (Personal)                        │
   │   -------------------------                        │
   │                                                    │
   │          Email : andychilton@gmail.com             │
   │            Web : https://chilts.org                │
   │        Twitter : https://twitter.com/andychilton   │
   │         GitHub : https://github.com/chilts         │
   │         GitLab : https://gitlab.org/chilts         │
   │                                                    │
   │   Apps Attic Ltd (My Company)                      │
   │   ---------------------------                      │
   │                                                    │
   │          Email : chilts@appsattic.com              │
   │            Web : https://appsattic.com             │
   │        Twitter : https://twitter.com/AppsAttic     │
   │         GitLab : https://gitlab.com/appsattic      │
   │                                                    │
   │   Node.js / npm                                    │
   │   -------------                                    │
   │                                                    │
   │        Profile : https://www.npmjs.com/~chilts     │
   │           Card : $ npx chilts                      │
   │                                                    │
   ╘════════════════════════════════════════════════════╛

(Ends)

Package Sidebar

Install

npm i @reacthooks.org/use-set-timeout

Weekly Downloads

0

Version

1.0.8

License

ISC

Unpacked Size

7.91 kB

Total Files

5

Last publish

Collaborators

  • chilts
  • chilts-appsattic