Last active
January 9, 2021 00:21
-
-
Save tfiechowski/2b70fae728b5e21c7fb1bce6932d7cda 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 { useCallback, useState } from "react"; | |
import { wait } from "./src/FunctionalUpdates/wait"; | |
export function FunctionalUpdates() { | |
const [counter, setCounter] = useState(0); | |
function handleIncrement() { | |
setCounter(counter + 1); | |
} | |
const handleIncrementCallback = useCallback(async () => { | |
await wait({ miliseconds: 2000 }); | |
setCounter(counter + 1); | |
}, [counter, setCounter]); | |
return ( | |
<div> | |
<div>Counter value: {counter}</div> | |
<button onClick={handleIncrement}> | |
Increment | |
</button> | |
<button onClick={handleIncrementCallback}> | |
Increment useCallback | |
</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment