Skip to content

Commit

Permalink
main 🧊 change demo for use latest
Browse files Browse the repository at this point in the history
  • Loading branch information
debabin committed Feb 5, 2025
1 parent f98326a commit 3bffa83
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/hooks/useLatest/useLatest.demo.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { useEffect, useState } from 'react';

import { useCounter } from '../useCounter/useCounter';
import { useLatest } from './useLatest';

const Demo = () => {
const [count, setCount] = useState(0);
const latestCount = useLatest(count);

useEffect(() => {
const interval = setInterval(() => setCount(count + 1), 1000);
return () => clearInterval(interval);
}, []);
const counter = useCounter();
const latestCount = useLatest(counter.value);

return (
<div>
<p>Count: <code>{count}</code></p>
<p>Latest count: <code>{latestCount}</code></p>
<p>You clicked <code>{counter.value}</code> times, latest count is <code>{latestCount}</code></p>

<button className='button' type='button' onClick={() => counter.inc()}>
Increment
</button>
</div>
);
};
Expand Down

0 comments on commit 3bffa83

Please sign in to comment.