在react中使用map或者其餘方法生成DOM時常常看到以下警告:html
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.
react
這是由於咱們沒有爲其綁定一個key={}形成的,關於key的做用:spa
https://reactjs.org/docs/lists-and-keys.htmlorm
更深刻的解釋:htm
https://react.docschina.org/docs/reconciliation.html#索引
使用了索引做爲key後可能形成的反作用:ci
https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318get