mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
fix: display alert timeout in story
This commit is contained in:
parent
5488f5eb3e
commit
2bb65ef3d8
@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user