<div class="container"></div>
const {useRef} = React

const App = () => {
  const count = useRef(0);
  return (
    <>
      <button onClick={() => count.current++}>カウント</button>
      <button onClick={() => alert(count.current)}>結果</button>
    </>
  );
};

ReactDOM.render(<App />, document.querySelector(".container"));
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js
  3. https://cdn.skypack.dev/@types/react@17.0.4