Answer the question
In order to leave comments, you need to log in
How to wait for the execution of the function, and then execute the condition?
There are 2 functions checkNicknames() and ckechNikname(). Function
export const checkNicknames = (nicknames) => {
let result = [];
nicknames.map( nickname => {
if (nickname) {
let st = ckechNikname(nickname);
st && result.push(st)
}
});
return result;
};
From this function, the data is transferred to the .jsx file and entered into the state there. const ckechNikname = (nickname) => {
let isParam = true;
let params = {};
getAccountId(nickname).then( async (data) => {
let account_id = data.data.data[0].account_id;
await getStatistic1(account_id).then(data => {
//обработка полученных данных по первому запросу
});
await getStatistic2(account_id).then(data => {
//обработка полученных данных по второму запросу
});
});
if (isParam) { return params} else { return false; }
};
getAccountId, getStatistic1, getStatistic2 - requests to the server. All data is displayed correctly when outputting to the console, but when passed in the condition, as I understand it, they do not have time to be entered into variables like isParam and params by this moment. How to make sure that all data is transferred?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question