58
rated 0 times
[
60]
[
2]
/ answers: 1 / hits: 9116
/ 4 Years ago, mon, july 27, 2020, 12:00:00
I have a state that should be a dictionary like so:
[personInfo, setPersonInfo] = useState({"firstName": "", "lastName": ""});
I want to update this state like so:
setPersonInfo(prevPersonInfo => prevPersonInfo["firstName"] = "name")
But this is not working.
Please do not recommend that I store two separate states for firstName and lastName. For my particular use case, it is necessary that I use a dictionary.
More From » reactjs