Skip to content

Instantly share code, notes, and snippets.

@tfiechowski
Created January 9, 2021 13:52
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/d5e9577c07f5b416161cf16ec7410ceb to your computer and use it in GitHub Desktop.
Save tfiechowski/d5e9577c07f5b416161cf16ec7410ceb 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 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