簡體   English   中英

React JS - 錯誤 - 需要賦值或 function 調用,而是看到一個表達式 no-unused-expressions

[英]React JS - Error - Expected an assignment or function call and instead saw an expression no-unused-expressions

我正在使用 Axios function 來返回 API 調用響應數據,如下所示。

componentDidMount(){
 axios.get("https://api.covid19india.org/state_district_wise.json").then(response => {
      response.data 
      this.setState({stateData:response.data});
   });
}

但是我在編譯時收到以下錯誤。 Expected an assignment or function call and instead saw an expression no-unused-expressions 當我刪除行respose.data時,它正在工作。 但不返回結果。

請幫忙

改成:

axios.get("https://api.covid19india.org/state_district_wise.json").then(response=>{
    this.setState({stateData:response.data});
    return response.data ;
});

then(response => {/* function body */}){}中的代碼是一個 function 的 body, then返回那個 ZC1C425268E68385D1AB5074C17A 的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM