简体   繁体   中英

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,

Warning: Each child in a list should have a unique "key" prop. Check the render method of Accordion

Accordion.js being one of my components of my Web Application

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. Could it be that I need to pass a key in my test score paragraph?

在此处输入图像描述

在此处输入图像描述

On line 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.

It is not recommended to use counter (0, 1, 2...) as your key when populating children.
You should use uuid() or item's self-identifier .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM