Counters that update separately

PHOTO EMBED

Tue Sep 20 2022 19:16:50 GMT+0000 (Coordinated Universal Time)

Saved by @bfpulliam #react.js

import { useState } from 'react';

function MyButton() {
  const [count, setCount] = useState(0);

  function handleClick() {
    setCount(count + 1);
  }

  return (
    <button onClick={handleClick}>
      Clicked {count} times
    </button>
  );
}

export default function MyApp() {
  return (
    <div>
      <h1>Counters that update separately</h1>
      <MyButton />
      <MyButton />
    </div>
  );
}
content_copyCOPY