fix: display alert timeout in story

This commit is contained in:
Clément Paris 2020-05-13 19:07:33 +02:00
parent 5488f5eb3e
commit 2bb65ef3d8

View File

@ -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>
);
};