關於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