收到错误消息:“类型'void'无法分配给类型'ReactNode'”

时间:2019-05-20 03:31:41

标签: javascript reactjs typescript

我正在尝试调用此函数

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

   }

每当我致电{this.compatiblelist()}

时,都会出现错误

函数CompatibleDevicesAPI()看起来像这样

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 个答案:

答案 0 :(得分:1)

我认为您只需要添加退货

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