3

I'm trying to call this function

    compatiblelist() {
         CompatibleDevicesAPI().then(
           response => {this.getCompatList(response)}
       );

   }

It's giving an error whenever I call {this.compatiblelist()}

The function CompatibleDevicesAPI() looks like this

export default function CompatibleDevicesAPI() {
    return fetch("https://abc/jjklsd/jlasd").then((res) => {
        let results = [];
        for(var i=0;i<res.response.docs.length;i++){
            let obj ={
                'compManufacturer': res.response.docs[i].comanufacturer,
                'comDisplayName': res.response.docs[i].comDisplayName ,
                'id' : res.response.docs[i].id,
            }
            results.push(obj);
        }
        return results;
    }).catch((error) => {
        let results = [];
        results.push({
            'comManufacturer': 'error',
            'comDisplayName': error
        })
        return results;
    });
}
Blue
  • 22,608
  • 7
  • 62
  • 92
Krish
  • 43
  • 1
  • 1
  • 5
  • What do you want the function to do? And please post the code that calls the function – yonBav May 20 '19 at 03:35
  • this.getCompatList(response) -> I want the response to be passed to this function this.getCompatList . Here i am manipulating the response and displaying it on UI. I have a render function in which I'm calling
    {this.getcompatList()}
    – Krish May 20 '19 at 03:39
  • I just added the rest of the code – Krish May 20 '19 at 03:39
  • don't perform a side effect in render method, use ```componentDidUpdate``` instead – AsukaSong May 20 '19 at 06:18

1 Answers1

6

I think you just need to add return

.then( response => {return this.getCompatList(response)} )

yonBav
  • 1,695
  • 2
  • 17
  • 31