1// declare state using useState hook.
2// someState is set to someInitialState
3const [someState, setSomeState] = useState(someInitialState);
4
5// setSomeState updates the current state
6setSomeState(someOtherState);
1function DelayedCount() {
2 const [count, setCount] = useState(0);
3
4 const handleClickAsync = () => {
5 setTimeout(function delay() {
6 setCount(count => count + 1); }, 3000);
7 }
8
9 return (
10 <div>
11 {count}
12 <button onClick={handleClickAsync}>Increase async</button>
13 </div>
14 );
15}