I am using a React functional component where I want to update only a specific field of the state and retain the other values like before. Here's the state initialization -
const[value, setValue] = React.useState({
a: "5",
b: "6"
});
I wish to only update value of 'a' to something else, let's say 7 (whilst retaining the same value for 'b'). Currently I am doing this -
setValue(currValue => ({
...currValue,
a: "7"
}))
Is this wrong ? If yes, what's the correct way of doing it ?