Skip to main content

Hook useTimeout

Arguments

ArgumentsTypeMeaningPossible values
callbackfunctionThe function that will execute after the duration() => void
delaynumberDuration time to execute the callback() => void



Return

ElementTypeMeaning
startTimeoutfunctionThe function that used to start or resume timeout
pauseTimeoutfunctionFunction that pause timeout

startTimeout()

ArgumentsType
--

pauseTimeout()

ArgumentsType
--



Example

const App = () => {
const { startTimeout, pauseTimeout } = useTimeout(() => {
alert('Test')
}, 1000)

useEffect(() => {
// Run timeout
startTimeout()
// Pause timeout
setTimeout(() => pauseTimeout(), 500)
// Resume timeout
setTimeout(() => startTimeout(), 1000)
}, [])

return 'Hello World!'
}