useTimeoutWhen
Aboutβ
Takes a callback and fires it when a condition is true
Installationβ
npm install --save rooks
Importing the hookβ
import { useTimeoutWhen } from "rooks";
Usageβ
function Demo() {
const [start, setStart] = useState(false);
useTimeoutWhen(() => setStart(false), 2000, start);
return (
<>
<h1>Rooks: useTimeoutWhen example</h1>
<hr></hr>
<p>Click the button below to disable it for 2 seconds</p>
<button onClick={() => setStart(true)} disabled={start}>
Start timeout
</button>
</>
);
}
render(<Demo />);
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 |
when | boolean | The condition which when true, sets the timeout | true |
Returnedβ
No return value.
Codesandbox Examplesβ
Basic Usageβ
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.