繁体   English   中英

反应 - 箭头主体周围的意外块语句

[英]react - Unexpected block statement surrounding arrow body

我有一个数组


const reportOptions = [
  {
    id: 1,
    title: 'Report',
  },
  {
    id: 2,
    title: 'Report 2',
  },
  {
    id: 3,
    title: 'Report 3',
  },
]

我尝试创建如下所示的新状态

  const [isReportsDownloading, setIsReportsDownloading] = useState(
    reportOptions.map(opt => {
      return { ...opt, isDownloading: false }
    })
  )

它给了我这个错误

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`

怎么修?

我认为该错误意味着这一点,尽管您的原始代码似乎已经有效,可能只是一个 eslint 错误。

 const [isReportsDownloading, setIsReportsDownloading] = useState( reportOptions.map((opt) => ({ ...opt, isDownloading: false })) );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM