Skip to content

Instantly share code, notes, and snippets.

@tfiechowski
Last active January 9, 2021 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfiechowski/54564903c448d15fdbe82262699a3391 to your computer and use it in GitHub Desktop.
Save tfiechowski/54564903c448d15fdbe82262699a3391 to your computer and use it in GitHub Desktop.
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