Skip to content

Commit

Permalink
fix: display alert timeout in story
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementParis016 committed May 13, 2020
1 parent 5488f5e commit 2bb65ef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stories/useLatest.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import ShowDocs from './util/ShowDocs';
const Demo = () => {
const [count, setCount] = React.useState(0);
const latestCount = useLatest(count);
const timeoutMs = 3000;

function handleAlertClick() {
setTimeout(() => {
alert(`Latest count value: ${latestCount.current}`);
}, 3000);
}, timeoutMs);
}

return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
<button onClick={handleAlertClick}>Show alert</button>
<button onClick={handleAlertClick}>Show alert in {timeoutMs / 1000}s</button>
</div>
);
};
Expand Down

0 comments on commit 2bb65ef

Please sign in to comment.