关于react循环渲染中的key


在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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM