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

posted @ 2022-03-10 11:23  lishidefengchen  阅读(53)  评论(0编辑  收藏  举报