I am a beginner in React. I have a setState from my async await function which calls an API. after calling the API, there are some issues happen since my state doesn't update immediately. How can I await my setState funcion so that it changes when the latest data was pulled?
Here is my whole function.
const getTimeLogsFromAPI = async () => {
const person_id = props.profile.basic_information.primary_information.id;
const uuid = props.profile.basic_information.primary_information.uuid_qrcode;
const new_format_date = dateFormatter(new Date(state.selectedDate));
const response = await fetch(`${getDjangoApiHost()}/api/jobnet_app/pass_check/${uuid}/?specific_month=${new_format_date}&person_id=${person_id}`);
const dataTimeLogs = await response.json();
if (dataTimeLogs) {
await setTimeLogs(dataTimeLogs)
}
if (timeLogs) {
await setShowDTR(true);
}
}