<html>
<head>
<meta charset="UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/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() {
// Define state variables for the two numbers and the result
const [num1, setNum1] = useState(10);
const [num2, setNum2] = useState(5);
const [result, setResult] = useState();
// Function to handle the subtraction
const handleSubtraction = () => {
const subtractionResult = num1 - num2;
setResult(subtractionResult);
};
return (
<div className='container'>
<h1 className='title'>React Js Subtract Two Number</h1>
<label className='label'>First Number</label>
<input
type="number"
className='input'
value={num1}
onChange={(e) => setNum1(Number(e.target.value))}
/>
<label className='label'>Second Number</label>
<input
type="number"
className='input'
value={num2}
onChange={(e) => setNum2(Number(e.target.value))}
/>
<button className='button' onClick={handleSubtraction}>Subtract</button>
<p className='result'>Result: {result}</p>
</div>
);
}
ReactDOM.render(<App />, document.getElementById("app"));
</script>
<style>
.container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* Styles for the title */
.title {
font-size: 24px;
color: #333;
margin-bottom: 20px;
}
/* Styles for the labels */
.label {
font-size: 16px;
color: #666;
display: block;
margin-bottom: 6px;
}
/* Styles for the input fields */
.input {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
/* Styles for the button */
.button {
background-color: #007bff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.button:hover {
background-color: #0056b3;
}
/* Styles for the result */
.result {
font-size: 18px;
color: #333;
margin-top: 20px;
}
</style>
</body>
</html>