查找: 索引 as 键
找错误 中等
题目
什么是 错误使用 using 索引 as 键这里?
代码
{items.map((item, index) => (
<li key={index}>{item.name}</li>
))}
// items can be reordered or items can be removed
提示
什么 happens 到索引当 项是 移除 or reordered?
解释
Using 数组索引 as 键是 problematic 当项 能是 reordered, inserted, or 移除. 索引 shift, causing React 到不正确地 reuse DOM 节点 and leading 到 subtle 状态 bugs. fix 是到 use stable 唯一 ID: 键={项.id}.
相关资源
相关课程
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。