Skip to content

Instantly share code, notes, and snippets.

@rockiger
Created February 19, 2021 08:37
Show Gist options
  • Save rockiger/c08e889b4df2f417491f188d3fb6fea7 to your computer and use it in GitHub Desktop.
Save rockiger/c08e889b4df2f417491f188d3fb6fea7 to your computer and use it in GitHub Desktop.
function Counter({initialCount: 42}) {
const [count, setCount] = useState(initialCount);
return (
<>
Count: {count}
<button onClick={() => setCount(initialCount)}>Reset</button>
<button onClick={() => setCount(prevCount => prevCount - 1)}>-</button>
<button onClick={() => setCount(prevCount => prevCount + 1)}>+</button>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment