react列表key滿足這些條件可以直接使用數組索引

  1. the list and items are static–they are not computed and do not change;
  2. the items in the list have no ids;
  3. the list is never reordered or filtered.

When all of them are met, you may safely use the index as a key.

 

參考:Index as a key is an anti-pattern (React) | by Robin Pokorny | Medium

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章