screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.14.0/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.14.0/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState} = React; function App() { const [num1, setNum1] = useState(10); const [num2, setNum2] = useState(23); const [result, setResult] = useState(0); const handleNum1Change = (event) => { setNum1(Number(event.target.value)); }; const handleNum2Change = (event) => { setNum2(Number(event.target.value)); }; const handleAddition = () => { setResult(num1 + num2); }; return ( <div className="container"> <h3 className="title">React Js Add Two Numbers</h3> <input type="number" className="input" value={num1} onChange={handleNum1Change} /> <input type="number" className="input" value={num2} onChange={handleNum2Change} /> <button className="button" onClick={handleAddition}> Add </button> <p className="result">Result: {result}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { margin: 0 auto; width: 500px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; display: flex; flex-direction: column; align-items: center; } .title { font-size: 24px; margin-bottom: 20px; } .input { width: 200px; padding: 10px; margin-bottom: 10px; } .button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; } .result { margin-top: 20px; } </style> </body> </html>