[英]React JS - Error - Expected an assignment or function call and instead saw an expression no-unused-expressions
I am using Axios function, to return an API call to response data as below.我正在使用 Axios function 来返回 API 调用响应数据,如下所示。
componentDidMount(){
axios.get("https://api.covid19india.org/state_district_wise.json").then(response => {
response.data
this.setState({stateData:response.data});
});
}
But I am getting the below error while compiling.但是我在编译时收到以下错误。
Expected an assignment or function call and instead saw an expression no-unused-expressions
. Expected an assignment or function call and instead saw an expression no-unused-expressions
。 When I remove the line respose.data
, it is working.当我删除行
respose.data
时,它正在工作。 But not returning the result.但不返回结果。
Please help请帮忙
Change to:改成:
axios.get("https://api.covid19india.org/state_district_wise.json").then(response=>{
this.setState({stateData:response.data});
return response.data ;
});
The code in {}
of then(response => {/* function body */})
is the body of a function, and then
returns the result of that function. then(response => {/* function body */})
的{}
中的代码是一个 function 的 body, then
返回那个 ZC1C425268E68385D1AB5074C17A 的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.