简体   繁体   English

React JS - 错误 - 需要赋值或 function 调用,而是看到一个表达式 no-unused-expressions

[英]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.

相关问题 反应中的 p5 js:期望赋值或函数调用,而是看到一个表达式 no-unused-expressions - p5 js in react : Expected an assignment or function call and instead saw an expression no-unused-expressions 期望一个赋值或 function 调用,而是看到一个表达式 no-unused-expressions - React Js Crud - Expected an assignment or function call and instead saw an expression no-unused-expressions - React Js Crud 得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions - getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react 期望一个赋值或函数调用,而是在React中看到一个表达式no-unused-expressions错误 - Expected an assignment or function call and instead saw an expression no-unused-expressions error in React 重定向(反应路由器dom),给出了期望的赋值或函数调用,而是看到了一个表达式no-unused-expressions - Redirect (react router dom) giving Expected an assignment or function call and instead saw an expression no-unused-expressions IONIC / REACT 第 9:5 行:期望一个赋值或函数调用,而是看到一个表达式 @typescript-eslint/no-unused-expressions - IONIC / REACT Line 9:5: Expected an assignment or function call and instead saw an expression @typescript-eslint/no-unused-expressions 期望分配或 function 调用,而是看到一个表达式 @typescript-eslint/no-unused-expressions (React) - Expected an assignment or function call and instead saw an expression @typescript-eslint/no-unused-expressions (React) 简单的反应组件 - 预期分配或 function 调用,而是看到一个表达式 no-unused-expressions - Simple react component - Expected an assignment or function call and instead saw an expression no-unused-expressions 在React中导入文件时,获得期望的赋值或函数调用,而是看到一个表达式no-unused-expressions - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions, when import a file in React 反应:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions - React: expected an assignment or function call and instead saw an expression no-unused-expressions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM