I have a React state object (myData) set as below (via React.useState)
{
myPayloadInfo: myData.myPayloadInfo,
isOriginDetails: true,
originSuccessMsg: null
}
myData.myPayloadInfo looks as below
{
"someVersion": 1,
"someFlag": false
}
Now, I want to update "someFlag" to true in the overall "myData". How can I do that using the spread operator ?
2
Answers
Since you mentioned that you have used
useState
, I assume that you have used it as,To update the
someFlag
, You have to doUnless I am missing the point, just spreading the full object, and then digging down to any required specifics should do the job: