【发布时间】:2021-07-04 11:47:37
【问题描述】:
我不知道为什么即使添加了密钥,反应仍然不断要求密钥。
我有一个渲染一些帖子的组件,但每个帖子都在它自己的组件中渲染,并且它位于来自 Swiper
的组件内我的组件如下所示:
export default function Posts() {
const postsCards = posts.map(post => {
return <SwiperSlide className="w-25" key={post._id}>
<PostCard post={post} key={post._id}/>
</SwiperSlide>
})
return (
<div className="container">
<h4>Top posts</h4>
<Swiper
slidesPerView= 'auto'
spaceBetween= {10}
observer= {true}
observeParents={true}
>
{postsCards}
</Swiper>
</div>
)
}
【问题讨论】:
-
它说键应该是唯一的。使用 post._id 检查它们是否不相同。此外,您可能还想显示明信片代码。