How can I change only a few states in an object useState? For example:
const [team, setTeam] = useState({
manager: "",
captain: "",
goalkeeper: "",
defender: "" })
Now I only want to update the value manager and goalkeeper at the same time. How is that possible?
I tried:
setTeam({ ...team, manager: newValue });
setTeam({ ...team, captain: newValue2 });
But it updates only one of those.
I also tried:
setTeam({ ...team, manager: newValue, captain: newValue2 });
It didn't work.
It is possible to change only a certain amount of variables in an useState object?
Thank you for any help!
Aucun commentaire:
Enregistrer un commentaire