在react中使用map或者其他方法生成DOM时经常看到如下警告:

index.js:1446 Warning: Each child in an array or iterator should have a unique "key" prop. See https://fb.me/react-warning-keys for more information.

这是因为我们没有为其绑定一个key={}造成的,关于key的作用:

https://reactjs.org/docs/lists-and-keys.html

更深入的解释:

https://react.docschina.org/docs/reconciliation.html#

使用了索引作为key后可能造成的副作用:

https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-04-26
  • 2021-09-30
  • 2022-12-23
  • 2021-07-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2021-06-03
相关资源
相似解决方案