<div id="root"></div>
const { useState } = React;

const App = () => {
  const [inputNum, setInputNum] = useState(0);
  const handleInputNum = (e) => {
    const { value } = e.target;
    setInputNum(value);
  };

  return (
    <>
      <div className="input-num">
        <h2>請輸入數字</h2>
        <input
          type="number"
          onChange={handleInputNum}
          value={inputNum}
          min="0"
        />
      </div>
      <div className="result">
        <h2>顯示輸入數字</h2>
        <input type="number" value={inputNum} />
      </div>
    </>
  );
};

ReactDOM.render(
  <div>
    <App />
  </div>,
  document.querySelector("#root")
);
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.0/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.0/umd/react-dom.production.min.js