Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 警告:数组或迭代器中的每个子级都应具有唯一的;“关键”;道具检查“CatList”的渲染方法`_Reactjs_React Redux - Fatal编程技术网

Reactjs 警告:数组或迭代器中的每个子级都应具有唯一的;“关键”;道具检查“CatList”的渲染方法`

Reactjs 警告:数组或迭代器中的每个子级都应具有唯一的;“关键”;道具检查“CatList”的渲染方法`,reactjs,react-redux,Reactjs,React Redux,我收到一条警告,要求使用“关键点”道具,但我正在CatList组件中使用关键点道具。见下文: import React from 'react'; import PropTypes from 'prop-types'; import {Link} from 'react-router-dom'; const CatList = ({cats}) => { return ( <ul className="list-group"> {cats.ma

我收到一条警告,要求使用“关键点”道具,但我正在CatList组件中使用关键点道具。见下文:

import React from 'react';
import PropTypes from 'prop-types';
import {Link} from 'react-router-dom';

const CatList = ({cats}) => {
  return (
      <ul className="list-group">
        {cats.map(cat =>
           <li className="list-group-item" key={cat.id}>
            <Link to={'/cats/' + cat.id}>{cat.name}</Link>
           </li>
        )}
      </ul>
  );
};

CatList.propTypes = {
  cats: PropTypes.array.isRequired
};

export default CatList;
从“React”导入React;
从“道具类型”导入道具类型;
从'react router dom'导入{Link};
常量CatList=({cats})=>{
返回(
    {cats.map(cat=>
  • {cat.name}
  • )}
); }; CatList.propTypes={ 猫:需要PropTypes.array.isRequired }; 导出默认CatList;

知道我为什么仍然收到这个React警告吗?

你有没有可能在你的
cats
数组中多次出现相同的
cat.id
?尝试
console.log
记录该值,并查看是否有可能在
cats
数组中多次复制相同的
cat.id
?尝试
console.log
记录该值,并查看可能存在的重复项