I’m working in React. I’m using useState
to hold an object in state. To make one change to the object and return it I can use the spread operator like so …
const [formWizard, setFormWizard] = useState(FORM_CONTROLS.steps[index]);
...
const addSection = section => {
...
setFormWizard(wizard => ({
...wizard,
wizard: formWizard.controls[14].group.push(...subjectAddressCopy.slice(0, 5))
}));
}
But what if I need to make multiple changes? I’ve tried putting a comma between them, use &&, and wrapping it in an object (though I think that would change the data structure). In either event known of those things worked.
setFormWizard(wizard => ({
...wizard,
wizard: formWizard.controls[14].group.push(...subjectAddressCopy.slice(0, 5),
formWizard.controls[14].trash) // how can I also make this change?
}));
How can I make two changes to formWizard and return it?