Last active
January 9, 2021 10:13
-
-
Save tfiechowski/54564903c448d15fdbe82262699a3391 to your computer and use it in GitHub Desktop.
This file contains 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 handleIncrementFunctional() { | |
await wait({ milisecomds: 2000 }); | |
setCounter(_counter => _counter + 1); | |
} | |
return ( | |
<div> | |
<div>Counter value: {counter}</div> | |
<button onClick={handleIncrement}>Increment</button> | |
<button onClick={handleIncrementFunctional}>Increment functional</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment