1.0.4 • Published 4 years ago

use-set-timeout v1.0.4

Weekly downloads
601
License
ISC
Repository
gitlab
Last release
4 years ago

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)

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago