Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Last active June 7, 2021 10:05
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 qkreltms/f62c434212c742563deb8ec5348d522c to your computer and use it in GitHub Desktop.
Save qkreltms/f62c434212c742563deb8ec5348d522c to your computer and use it in GitHub Desktop.
function CountButton({onClick, count}:{onClick:()=>void, count: number}) {
  return <button onClick={onClick}>{count}</button>
}
function DualCounter() {
  const [count1, setCount1] = React.useState(0)
  const increment1 = () => setCount1(c => c + 1)
  const [count2, setCount2] = React.useState(0)
  const increment2 = () => setCount2(c => c + 1)
  return (
    <>
      <CountButton count={count1} onClick={increment1} />
      <CountButton count={count2} onClick={increment2} />
    </>
  )
}
export default DualCounter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment