You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
568 B
23 lines
568 B
/**
|
|
* Returns a controller object for setting a timeout that is properly cleaned up
|
|
* once the component unmounts. New timeouts cancel and replace existing ones.
|
|
*
|
|
*
|
|
*
|
|
* ```tsx
|
|
* const { set, clear } = useTimeout();
|
|
* const [hello, showHello] = useState(false);
|
|
* //Display hello after 5 seconds
|
|
* set(() => showHello(true), 5000);
|
|
* return (
|
|
* <div className="App">
|
|
* {hello ? <h3>Hello</h3> : null}
|
|
* </div>
|
|
* );
|
|
* ```
|
|
*/
|
|
export default function useTimeout(): {
|
|
set: (fn: () => void, delayMs?: number) => void;
|
|
clear: () => void;
|
|
};
|