Skip to content

Commit 3bffa83

Browse files
committed
main 🧊 change demo for use latest
1 parent f98326a commit 3bffa83

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

‎src/hooks/useLatest/useLatest.demo.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import { useEffect, useState } from 'react';
2-
1+
import { useCounter } from '../useCounter/useCounter';
32
import { useLatest } from './useLatest';
43

54
const Demo = () => {
6-
const [count, setCount] = useState(0);
7-
const latestCount = useLatest(count);
8-
9-
useEffect(() => {
10-
const interval = setInterval(() => setCount(count + 1), 1000);
11-
return () => clearInterval(interval);
12-
}, []);
5+
const counter = useCounter();
6+
const latestCount = useLatest(counter.value);
137

148
return (
159
<div>
16-
<p>Count: <code>{count}</code></p>
17-
<p>Latest count: <code>{latestCount}</code></p>
10+
<p>You clicked <code>{counter.value}</code> times, latest count is <code>{latestCount}</code></p>
11+
12+
<button className='button' type='button' onClick={() => counter.inc()}>
13+
Increment
14+
</button>
1815
</div>
1916
);
2017
};

0 commit comments

Comments
 (0)