简体   繁体   English

如何解决这个 Reactjs Eslint 关于 'index' 的警告已定义但从未使用

[英]How to solve this Reactjs Eslint warning about 'index' is defined but never used

Feels like a mistake to me how can I not have an "index" when iterate a map.对我来说感觉像是一个错误,在迭代地图时我怎么能没有“索引”。 Any ide?任何想法?

在此处输入图片说明

You're not using the index returned from the map function.您没有使用从 map 函数返回的索引。 You're declaring 'id' inside of it and assigning a value returned from "uniqueId" somewhere else in your code.您在其中声明了 'id' 并在代码中的其他地方分配了从“uniqueId”返回的值。

This is not a bug.这不是一个错误。

If you don't want to see the warning, you could:如果您不想看到警告,您可以:

  • not use "index", since in fact you're not using it.不要使用“索引”,因为实际上您没有使用它。
  • replace it with _ , that way eslint will understand that you're discarding that parameter_替换它,这样 eslint 就会明白你正在丢弃那个参数

Edit: As pointed by Brian Thompson, you probably want to use the index anyway, to get a unique id without having to create one by yourself:编辑:正如 Brian Thompson 所指出的,您可能无论如何都想使用索引来获得唯一的 id,而不必自己创建一个:

Resume.article.map((element, idx) => {
  articles.push(
    <div className="column" key={idx}>
      ...
    </div>
  )
}

You're not using/referencing index anywhere, so just remove it from the parameters.您没有在任何地方使用/引用index ,因此只需将其从参数中删除即可。 You don't need it.你不需要它。

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

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