Working with Multiple Inputs in React
Let's say we have two inputs where numbers will be entered. Let's make it so that as you enter numbers into a paragraph, the sum of the two inputs is displayed:
function App() {
const [value1, setValue1] = useState(0);
const [value2, setValue2] = useState(0);
function handleChange1(event) {
setValue1(+event.target.value);
}
function handleChange2(event) {
setValue2(+event.target.value);
}
return <div>
<input value={value1} onChange={handleChange1} />
<input value={value2} onChange={handleChange2} />
<p>result: {value1 + value2}</p>
</div>
}
Given 5
inputs. Make it so that when entering numbers into our inputs, the arithmetic mean of the entered numbers is displayed in the paragraph.