In my simplified code:
static getData(Id) {
const data = [];
api.getData(lId)
.then((Res) => {
data.push(Res);
});
return data;
}
The API endpoint gets the data but it takes some time. the method always returns [], but if I put a console.log(Res), the data is there. It means the method returns the initial const data = [];
and it doesn't wait until the API returns the data.
How should I fix this problem?
Regrds