Version: v3.6.0

@rooks/use-timeout#

setTimeout hook for react.#


Build Status

Installation#

npm install --save @rooks/use-timeout

Importing the hook#

import useTimeout from "@rooks/use-timeout"

Usage#

function TimeoutComponent() {
function doAlert() {
window.alert("timeout expired!");
}
const { start, clear } = useTimeout(doAlert, 2000);
return (
<>
<button onClick={start}> Start timeout </button>
<button onClick={clear}> Clear timeout </button>
</>
);
}
render(<TimeoutComponent/>)

Arguments#

ArgumentsTypeDescriptionDefault value
callbackfunctionFunction to be executed in timeoutundefind
delayNumberNumber in milliseconds after which callback is to be run0

Returned Object keys#

Returned object attributesTypeDescription
clearfunctionClear the timeout
startfunctionStart the timeout
isActivebooleanIs the timeout active
Last updated on by imbhargav5