2022-05-31
Hello developer!, glad to see you again.
This is a react-curve, open source project where I can share and start creating small UI components in the way I understood the concepts to build large scale projects .
This week we created a Sum Two Numbers app. The user enter two numbers in a form and result of the summation is shown in react.
To create a SumTwoNum component; We have to :
import React, {useState} from 'react';
const SumTwoNum = () => {
const [number1, setNumber1] = useState();
const [number2, setNumber2] = useState();
const [summation, setSummation] = useState(0);
function calculate() {
setSummation(number1 + number2);
}
return (
<div>
<h2>Sum Two Numbers</h2>
<input
placeholder="First Number"
type="number"
value={number1}
onChange={(ev) => setNumber1(+ev.target.value)}
/>
<input
placeholder="Second Number"
type="number"
value={number2}
onChange={(ev) => setNumber2(+ev.target.value)}
/>
<br />
<button onClick={calculate}>Sum Two Numbers</button>
<p>Summation : {summation || "0"}</p>
</div>
);
}
export default SumTwoNum;
Thank you for reading and any contribution is more than welcome in the threads below!