我有一个反应组件,它一次生成许多键,我不确定哪个不是唯一的。错误如下。有什么简单的方法可以帮助调试吗?谢谢!
React.js:19500 警告:数组或迭代器中的每个子项都应该有一个唯一的“key”属性。检查渲染方法MyGrid
。请参阅 https://fb.me/react-warning-keys 了解更多信息。
这是一个警告,表明您尚未分配密钥,而不是它实际上不是唯一的,消息的下一行应该准确地告诉您有问题的元素是什么 - 请参阅下面的示例in div (created by CardsComponent)
warning.js:36 Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `CardsComponent`. See fb.me/react-warning-keys for more information.
in div (created by CardsComponent)
如果你想进一步调试,测试是在ReactElementValidator.validateExplicitKey
它只是检查元素键是否非空,不检查兄弟键之间的唯一性......
function validateExplicitKey(element, parentType) {
if (!element._store || element._store.validated || element.key != null) {
return;
}
// if it gets here it has failed and you will be warned
这里有趣的部分是element.key != null
当其他人通过已经被验证的美德时
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)