javascript - ES6 胖箭头 react this.setState ESLint 错误

标签 javascript reactjs ecmascript-6

我在 react 中有一小段代码

this.setState((prevState) => {
  return { userAnnotations: [...prevState.userAnnotations, selText] };
});

当 ES Lint 给出错误 [eslint] Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the 时,我如何将其转换为单行=> . (arrow-body-style)

我尝试删除 return 周围的大括号,但随后发生了另一个错误。

请帮忙。

最佳答案

您需要做的就是摆脱return

    this.setState(prevState => ({ userAnnotations: 
          [...prevState.userAnnotations, selText]
    }))

关于javascript - ES6 胖箭头 react this.setState ESLint 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48785613/

相关文章:

javascript - 鼠标悬停、鼠标悬停并单击谷歌地图上的同一标记

javascript - 向 html5 canvas 游戏添加计时器

javascript - Rails 应用程序中 native HTML 需要图像路径

javascript - 如何通过单击 react 路由器 v4 中的按钮在路径上导航?

javascript - 转换和过滤动态 JSON 返回的对象

javascript - 从下拉列表中更改文本输入不会更新选定的 div

javascript - 无法从 React 前端向 Node.js 后端发送 POST 请求

reactjs - React hooks useEffect : include some dependencies but ignore others

javascript - Webpack 无法从包的子目录中解析模块

javascript - 带有异步返回 Promise 的 Map