简体   繁体   English

React - 列表中的每个孩子都应该有一个唯一的“key”道具

[英]React - Each child in a list should have a unique “key” prop

I am working on a React Web Application Where I fetch and display student data from an API and I keep getting the error,我正在开发一个 React Web 应用程序,我从 API 获取并显示学生数据,但我一直收到错误,

Warning: Each child in a list should have a unique "key" prop.警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 Check the render method of Accordion检查Accordion的渲染方法

Accordion.js being one of my components of my Web Application Accordion.js 是我的 Web 应用程序的组件之一

Any Help to fix this issue would be appreciated:)任何解决此问题的帮助将不胜感激:)

I have tried passing a key prop with an id to the Accordion component from a parent component, but that did not seem to work.我尝试将带有 id 的 key prop 从父组件传递给 Accordion 组件,但这似乎不起作用。 Could it be that I need to pass a key in my test score paragraph?难道是我需要在我的考试成绩段落中传递一个关键吗?

在此处输入图像描述

在此处输入图像描述

On line 23在线 23

Make the following change进行以下更改

<p 

To

<p key={`${i}-stats`}

The issue is simple.问题很简单。 React needs to identify each sibling node uniquely and thus it asks you to pass key prop to sibling nodes when returning array or iterating over a lost to return component/view. React 需要唯一地标识每个兄弟节点,因此它要求您在返回数组或迭代丢失以返回组件/视图时将 key prop 传递给兄弟节点。

It is not recommended to use counter (0, 1, 2...) as your key when populating children.在填充子项时,不建议使用 counter (0, 1, 2...)作为您的
You should use uuid() or item's self-identifier .您应该使用uuid()或 item 的self-identifier

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 列表中的每个孩子都应该有一个唯一的“关键”道具/反应 - Each child in a list should have a unique "key" prop / react 反应错误:列表中的每个孩子都应该有一个唯一的“关键”道具 - React Error: Each child in a list should have a unique "key" prop React - 列表中的每个孩子都应该有一个唯一的“key”道具 - React - Each child in a list should have a unique “key” prop 反应警告:列表中的每个孩子都应该有一个唯一的“关键”道具 - React Warning: Each child in a list should have a unique "key" prop “反应”列表中的每个孩子都应该有一个唯一的“关键”道具 - "react" Each child in a list should have a unique "key" prop React,列表中的每个孩子都应该有一个唯一的 key prop - React, Each child in a list should have a unique key prop 警告:列表中的每个孩子都应该有一个唯一的“key”道具,即使它有唯一的 key React - Warning: Each child in a list should have a unique “key” prop even tho it has unique key React 反应警告:列表中的每个孩子都应该有一个唯一的“钥匙”道具,当钥匙被提供并且是唯一的 - React Warning: Each child in a list should have a unique "key" prop when key is provided and unique 反应警告:列表中的每个孩子都应该有一个唯一的“关键”道具不是由地图中缺少关键引起的 - React Warning: Each child in a list should have a unique "key" prop NOT caused by lack of key in map 列表中的每个孩子都应该有一个唯一的“关键”道具错误,以 uuid 作为关键反应 - Each child in a list should have a unique "key" prop error with uuid as key react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM