Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem when trying to fetch data from the Fetch API. Empty parentheses arrive before clicking in the console

I’m trying to get a data from fetch API. But my result is empty before i click on result in console. And i coudn’t manage this data in my app. I don’t have something, problem with asynchronous getting data from fetch

I tried to use other asynchronous methods to receive data, but all to no avail.

enter image description here
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If the actual method that gets remote data is async you need to make every method in your stack async and then await each return value. That’s why you are seeing the default value. For example…

// constroller.js
async getDataFromModel() {
  this._data = await model.getData();
  console.log(this._data);
}
// weatherModel.js
async getData() {
  return await this.getPosition();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading