【发布时间】:2021-04-28 11:47:51
【问题描述】:
当我尝试使用来自 Django 后端的 GraphQL 将数据提取到 React 前端时出现此错误 错误
index.js:1 Warning: Each child in a list should have a unique "key" prop. See https://reactjs.org/link/warning-keys for more information.
at EmployerInfo (http://localhost:3000/static/js/main.chunk.js:231:75)
at div
at ApolloProvider (http://localhost:3000/static/js/0.chunk.js:6401:19)
at App
这是在 React 前端获取的反应代码
const QUERY_EMPLOYERS = gql`
{
allEmployers{
edges{
node{
id
employerName
email
phone
}
}
}
}
`;
export function EmployerInfo() {
const { data, loading } = useQuery(QUERY_EMPLOYERS, {pollInterval: 500});
if (loading) return <p>Loading...</p>;
return data?.allEmployers.edges.map(({ id, employerName, email, phone }) => (
<div key={ id }>
<p>
Employer - { employerName } { email } { phone }
</p>
</div>
));
}
【问题讨论】: