mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-23 00:45:16 +00:00
23 lines
568 B
TypeScript
23 lines
568 B
TypeScript
/**
|
|
* 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;
|
|
};
|