Skip to content

use-timeout-effect ​

  • A hooks which fires the provided callback only once when the given delay is passed, just like the setTimeout.

Parameters ​

ParameterTypeRequiredDefault ValueDescription
cbFunction✅-Callback to fire after given amount of timeout is passed.
timeoutnumber❌100Timeout value after which the callback is fired.

Returns ​

  • It returns an object.
  • clearTimer : () => void
  • restartTimer : () => void

Usage ​

ts
import { useState } from 'react'
import { useTimeoutEffect } from 'classic-react-hooks'

export default function YourComponent() {
   const [show, setShow] = useState(false)

   useTimeoutEffect(() => {
      console.log('use-timeout-callback')
      setShow(true)
   }, 2000)

   return <div>{show && <div>show</div>}</div>
}