use-timeout
Aboutβ
setTimeout hook for react.
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β
Arguments | Type | Description | Default value |
---|---|---|---|
callback | function | Function to be executed in timeout | undefind |
delay | Number | Number in milliseconds after which callback is to be run | 0 |
Returned Object keysβ
Returned object attributes | Type | Description |
---|---|---|
clear | function | Clear the timeout |
start | function | Start the timeout |
isActive | boolean | Is the timeout active |
Join Bhargav's discord serverβ
You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.