【发布时间】:2019-06-23 11:34:05
【问题描述】:
我制作了一个创建组件,它可以渲染所有看起来不错的东西,但是当我在浏览器中执行控制台时,它出现以下错误。
index.js:2178 警告:数组或迭代器中的每个子元素都应该有 一个独特的“关键”道具。
我尝试了关键道具,但仍然出现此错误。请在下面查看我的代码并提出建议!非常感谢。
const serviceList = (props) => (
<CardBody style={{ backgroundImage: `url(${ServiceBgImg})` }}>
<div>
<h3 style={{ fontWeight: 'bold' }}
>{props.groupName}</h3>
{props.allServices.filter(groupedServices => groupedServices.category === props.groupName)
.map(serviceInfo =>
<List component='nav'>
<ListItem>
<ListItemText primary={
<div key={serviceInfo.id}>
<h5 style={{ fontWeight: 'bold' }}>
<span>{serviceInfo.service}</span>
<span
style={{ float: 'right' }}
>{serviceInfo.price}</span>
</h5>
<h5>
{serviceInfo.description}
</h5>
</div>
}
/>
</ListItem>
</List>
)
}
</div>
</CardBody>
);
export default serviceList;
【问题讨论】:
-
您的
List应该得到密钥,而不是List中的div
标签: reactjs key unique react-props