I have a function getData() like this:
const getData = () => {
const lsData = dummyJsonDataForTest;
if (condition) {
return lsData;
}
// call API here
apiService
.getData()
.then((json) => {
return json.data;
})
.catch(() => {
return null;
})
return null;
};
I want to return a response from the API call if the condition is false, but seems that the function getData() will return null before the API response.
Is there any way to make it wait for the response before the function return null?
Thank you in advance.