The below React component named SimpleForm uses the useState hook to manage state for a name input and an age input. Display the inputs and update the state as the user types. Display the entered name and age.
State
Forms
Report a typo
Fill in the gaps with the relevant elements
import React, { useState } from 'react';
const SimpleForm = () => {
const [name, ] = useState('');
const [age, ] = useState('');
return (
<div>
<label htmlFor="name">Name:</label>
<input
type="text"
id="name"
value={name}
onChange={(e) => setName()}
/>
<label htmlFor="age">Age:</label>
<input
type="text"
id="age"
value={}
onChange={(e) => setAge(e.target.value)}
/>
<p>Name: {name}</p>
<p>Age: {age}</p>
</div>
);
};
export default SimpleForm;Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.