Ive already had one question axios in javascript function to return data about this but it has been closed and I am still fighting this.
However I had some progress of sort.
class Api {
getPin = () => {
fetch("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => response.json())
.then((json) => this.getResults(json));
};
async getResults(data) {
let pin = await data;
console.log(pin.id);
}
}
let api = new Api();
api.getPin();
This will get API call and I am able to console log it (this is after 10 hours looking into this :'-() Ideally I would like to use the result elsewhere in the app
Could someone please help? I am struggling with this
EDIT:
class Api {
getPin = () => {
fetch("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => response.json())
.then((json) => this.getResults(json));
};
getResults(data) {
// console.log(data);
return data;
}
}
let api = new Api();
let pin = api.getPin();
console.log(pin);
if I get rid off the async and await and return data from function I am getting undefined when trying to console log. WHat am I still missing?