Skip to content

Commit 893e102

Browse files
authored
docs: added example for useTimeout (#38)
1 parent a868a6c commit 893e102

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/useTimeout.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ function setChainedTimeout(
3131
/**
3232
* Returns a controller object for setting a timeout that is properly cleaned up
3333
* once the component unmounts. New timeouts cancel and replace existing ones.
34+
*
35+
*
36+
*
37+
* ```tsx
38+
* const { set, clear } = useTimeout();
39+
* const [hello, showHello] = useState(false);
40+
* //Display hello after 5 seconds
41+
* set(() => showHello(true), 5000);
42+
* return (
43+
* <div className="App">
44+
* {hello ? <h3>Hello</h3> : null}
45+
* </div>
46+
* );
47+
* ```
3448
*/
3549
export default function useTimeout() {
3650
const isMounted = useMounted()

0 commit comments

Comments
 (0)