<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
This Pen doesn't use any external CSS resources.