2
votes

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;
    });
}
1
What do you want the function to do? And please post the code that calls the functionyonBav
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 <div>{this.getcompatList()}</div>Krish
I just added the rest of the codeKrish
don't perform a side effect in render method, use componentDidUpdate insteadAsukaSong

1 Answers

3
votes

I think you just need to add return

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