Hook useTimeout
Arguments
Arguments | Type | Meaning | Possible values |
---|---|---|---|
callback | function | The function that will execute after the duration | () => void |
delay | number | Duration time to execute the callback | () => void |
Return
Element | Type | Meaning |
---|---|---|
startTimeout | function | The function that used to start or resume timeout |
pauseTimeout | function | Function that pause timeout |
startTimeout()
Arguments | Type |
---|---|
- | - |
pauseTimeout()
Arguments | Type |
---|---|
- | - |
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!'
}