For Array and Dictionary useState hook is not updating it's value.
My Method:-
const [saveresponse, setSaveResponse] = useState({})
For to update saveresponse:-
const res={a:"1",b:"2"}
setSaveResponse(res)
Example function:-
const ComputeAndSaveTest = () => {
const res={a:"1",b:"2"}
setSaveResponse(res)
console.log(saveresponse) //Not updating
}
Also another function call after that function:-
onCompleted() {
console.log(saveresponse) //Not Updated
}
Same applied to Array.
I am new to react someone please suggest me best practice to solve it and please explain it if possible.
Thank you!