1

I am using the fetch library and I am trying this:

fetchtest() {
    fetch('someurl...').then((data) => {
        if (data.status === 200) {
            return true;
        }
    });

}

then to call it:

myMethod() {
    if (this.fetchtest()) {
        console.info('Would return true');
    }
}

It's not returning anything.

What I'm I doing wrong?

2 Answers2

0

This is happening because this.fetchtest() is returning a Promise which is 'truthy' in nature.

ajaybc
  • 4,049
  • 7
  • 44
  • 57
-1

It returns a promise so it may be not present at the time it is needed to be used.

vitomadio
  • 1,140
  • 8
  • 14