【发布时间】:2019-07-23 18:12:16
【问题描述】:
我正在从 JSON api 中提取数据。我在 map 函数生成的唯一元素中分配了一个键,但我不知道为什么我仍然看到这个警告。我需要在哪里分配密钥?
import React from 'react';
import PokeCell from './PokeCell';
import './styles/PokeList.css';
const PokeList = (props) => {
return (
<section className="poke-list">
{props.pokemon.map((pokemon) => (
<PokeCell
key={pokemon.id}
id={pokemon.id}
name={pokemon.name}
image={pokemon.image}
/>
))}
</section>
)
}
export default PokeList;
index.js:1375 Warning: Each child in a list should have a unique "key"
prop.
Check the render method of `PokeList`
in PokeCell (at PokeList.js:10)
in PokeList (at App.js:24)
in div (at App.js:20)
in App (at src/index.js:7)
【问题讨论】:
-
你把钥匙放在了正确的地方......在你回电话之前你能
clgprops.pokemon的ID吗? -
pokemon.id 的值有效吗?
标签: reactjs