元素使用數組索引這發出警告,react使用key已經更改,刪除應該是穩定:
建議修改:使用循環的 index 變量作為 key 是一種反優化。參考:https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
用數組索引不是一個好主意,因為他不能唯一的標識元素,在數組排序或者添加數組開頭情況下,即使該索引的元素可能是相同,該索引也將被更改,導致不必要的渲染,解決方法將key={index}改成key={ad.id}即可
參照:
https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
It's a bad idea to use the array index since it doesn't uniquely identify your elements. In cases where the array is sorted or an element is added to the beginning of the array, the index will be changed even though the element representing that index may be the same. This results in unnecessary renders.