Animation & Timing
useTimeoutWhen
About
Takes a callback and fires it when a condition is true
Examples
Basic usage
import "./styles.css";
import { useTimeoutWhen } from "rooks";
import { useState } from "react";
function App() {
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>
</>
);
}
export default App;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.