简体   繁体   English

列表中的每个孩子都应该有一个唯一的“钥匙”道具 Reactjs

[英]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.

相关问题 ReactJs-列表中的每个孩子应该有一个唯一的“关键”道具 - ReactJs - Each child in a list should have a unique “key” prop Reactjs:警告列表中的每个孩子都应该有一个唯一的“关键”道具 - Reactjs: Warning Each child in a list should have a unique "key" prop 数组或迭代器中的每个子代在reactjs中都应具有唯一的“键”道具 - Each child in an array or iterator should have a unique “key” prop in reactjs 警告:列表中的每个孩子都应该有一个唯一的“key”道具。 - ReactJS - Warning: Each child in a list should have a unique "key" prop. - ReactJS 修复警告 ///列表中的每个孩子都应该有一个唯一的“键”道具 - fixing warning ///Each child in a list should have a unique "key" prop 警告:列表中的每个孩子都应该有一个唯一的“键”道具来切换 - Warning: Each child in a list should have a unique "key" prop for switch “反应”列表中的每个孩子都应该有一个唯一的“关键”道具 - "react" Each child in a list should have a unique "key" prop 列表中的每个孩子都应该有唯一的“关键”道具 - each child in a list should have unique 'key' prop React - 列表中的每个孩子都应该有一个唯一的“key”道具 - React - Each child in a list should have a unique “key” prop 列表中的每个孩子都应该有一个唯一的 key prop - Each child in a list should have a unique key prop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM