【问题标题】:React JS esLint error Unexpected block statement surrounding arrow body; move the returned value immediately after the =>React JS esLint错误围绕箭头主体的意外块语句;在 => 之后立即移动返回的值
【发布时间】:2020-01-23 19:09:42
【问题描述】:

在我的 react jsx 文件中,我在一个表中有以下代码

render() {
  return(

  <Table>
  <thead>
    <tr>
    {
      this.collection.arraylist.map((name) => {
        return this.getMoreNames(name)
      }
    }
    </tr>
  </thead>
  <Table>
)}



esLint is give me the error as described in my post subject. I read other post and added () but that did not work

  this.collection.arraylist.map((name) => ({
        return this.getMoreNames(name)
   })

我尝试删除名称周围的括号,错误仍然存​​在。该代码有效,但我不确定如何解决此 lint 错误。

【问题讨论】:

    标签: reactjs eslint


    【解决方案1】:

    错误的措辞在我的选项中有点令人困惑,但它告诉您在单个 return 语句的情况下该块是不必要的。你的代码可以改写为:

    this.collection.arraylist.map(name => this.getMoreNames(name))
    

    请参阅documentation,详细了解箭头函数的工作原理。

    【讨论】:

      猜你喜欢
      • 2020-10-15
      • 2019-03-09
      • 2021-10-19
      • 2016-12-20
      • 1970-01-01
      • 2020-12-27
      • 2021-09-01
      • 2018-04-10
      • 1970-01-01
      相关资源
      最近更新 更多