Changing Data with a Function in React
It is not necessary to perform any operations on the state directly on the output. You can use the function:
function square(num) {
return num ** 2;
}
function App() {
const [value, setValue] = useState(0);
function handleChange(event) {
setValue(event.target.value);
}
return <div>
<input value={value} onChange={handleChange} />
<p>{square(value)}</p>
</div>;
}
Given an input and a paragraph. The user's age is entered into the input. Make it so that when typing, the user's year of birth automatically appears in the paragraph.
Given an input and a paragraph. The input contains degrees Fahrenheit. Make it so that when you type text, the paragraph automatically converts to degrees Celsius.