html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple React Calculator</title>
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function App() {
const [num1, setNum1] = React.useState(0);
const [num2, setNum2] = React.useState(0);
const [result, setResult] = React.useState(0);
function addNumbers() {
setResult(num1 + num2);
}
function subtractNumbers() {
setResult(num1 - num2);
}
return (
<div>
<input type="number" value={num1} onChange={e => setNum1(+e.target.value)} />
<input type="number" value={num2} onChange={e => setNum2(+e.target.value)} />
<button onClick={addNumbers}>Add</button>
<button onClick={subtractNumbers}>Subtract</button>
<h2>Result: {result}</h2>
</div>
);
}
ReactDOM.render(<App />, document.getElementById('root'));
</script>
</body>
</html>
html
Explain<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple React Calculator</title>
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function ButtonDigit({ digit, onClick }) {