Created
January 9, 2021 13:52
-
-
Save tfiechowski/d5e9577c07f5b416161cf16ec7410ceb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import { wait } from "./wait"; | |
export function FunctionalUpdates() { | |
const [counter, setCounter] = useState(0); | |
function handleIncrement() { | |
setCounter(counter + 1); | |
} | |
async function handleIncrementAsync() { | |
await wait({ miliseconds: 2000 }); | |
setCounter(counter + 1); | |
} | |
return ( | |
<div> | |
<div>Counter value: {counter}</div> | |
<button onClick={handleIncrement}>Increment</button> | |
<button onClick={handleIncrementAsync}>Increment asynchronously</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment