I'm new to React and I'm trying to make an Api call to a server then using this this data in my component.
I'm trying to use async await to handle asynchronous
const onNotifReceived = async (res) => {
var updatedQueue = res.updatedQueue;
updatedQueue["queueNewState"] = await getContactDetails(authClient, res.updatedQueue.queueNewState);
console.log(JSON.parse(JSON.stringify(updatedQueue)))
notifyQueue(updatedQueue); // redux dispatcher
}
I notice that console.log(JSON.parse(JSON.stringify(updatedQueue))) is run before other console.logsinside the function getContactDetails.
But as I know await should wait for the response before passing to the next line which is not the case and the problem that I'm not getting updatedQueue["queueNewState"] new state.