UNPKG

568 BTypeScriptView Raw
1/**
2 * Returns a controller object for setting a timeout that is properly cleaned up
3 * once the component unmounts. New timeouts cancel and replace existing ones.
4 *
5 *
6 *
7 * ```tsx
8 * const { set, clear } = useTimeout();
9 * const [hello, showHello] = useState(false);
10 * //Display hello after 5 seconds
11 * set(() => showHello(true), 5000);
12 * return (
13 * <div className="App">
14 * {hello ? <h3>Hello</h3> : null}
15 * </div>
16 * );
17 * ```
18 */
19export default function useTimeout(): {
20 set: (fn: () => void, delayMs?: number) => void;
21 clear: () => void;
22};