- Forums
- react
- React Usestate Update Simple Version - Nested Object Form Field Onchange Input
This is the very simple version to show how to update useState from a input field form. [5198], Last Updated: Mon Jun 24, 2024
cathy
Mon Sep 04, 2023
0 Comments
305 Visits
This is where you have multiple nested form object.
The value of textarea here is update to form.
Object Example:
const [form, setForm] = useState(
{
mathType: {
value: 'The textarea content default value'
},
});
The setForm updates form.mathType.value on Change
<textarea
onChange={(e) => setForm(
{...form, ['mathType']: {
...form['mathType'],
value: e.target.value
}
})}
></textarea>