[英]Each child in a list should have a unique "key" prop Reactjs
I am working on Nextjs/Reactjs i am fetching data after click on button but in my console i am getting following error我正在研究 Nextjs/Reactjs 我在点击按钮后获取数据但是在我的控制台中我收到以下错误
Each child in a list should have a unique "key" prop
Here is my current code ( data is displaying with id and title)(这是我当前的代码(数据显示有 id 和标题)(
<button onClick={fetchReviewsFromServer}>Load Reviews From Server</button>
{
reviewfromserver.map(reviewnew=>{
return(
<>
<div key={reviewnew.id}> // not working
<div>{reviewnew.id}- {reviewnew.title} </div>
</div>
</>
)
})
}
The child in your list is the empty <>
element, I don't see a need for it regardless, since you only have one child element to that element .列表中的子元素是空的
<>
元素,我认为无论如何都不需要它,因为该元素只有一个子元素。
<button onClick={fetchReviewsFromServer}>Load Reviews From Server</button>
{
reviewfromserver.map(reviewnew=>{
return(
<div key={reviewnew.id}> // not working
<div>{reviewnew.id}- {reviewnew.title} </div>
</div>
)
})
}
That's because the fragmets are items.那是因为碎片是物品。 Remove them, you don't need them anyway.
删除它们,反正你不需要它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.