0

I have a component called PostList that basically fetch my posts from the database , and render a Post component for each post , and I'm doing this way

 return(

posts.map(p => <Post 
  key={p.post_id} 
  category={p.category_name} 
  title={p.title} 
   description={p.description}></Post>))

I'm passing the post_id as a key to each one of my posts , but I get a error on the console saying that every child should have its own key , and it doesnt say where the error come from , but If I delete the posts it dissapear so I assume the error comes from there

the point is that each child has its own key since it is the id from the database that is a primary key I will show a picture that show clear that each one has a different key

Picture of the component

Thanks for the help

ManuC12
  • 33
  • 5
  • did you log out `posts` before returning ? The error might appear when posts are empty – Duc Hong May 09 '20 at 13:13
  • How does `posts` look like? Can you paste the sample here? – wentjun May 09 '20 at 13:13
  • @DucHong Thank you man , I found the error thanks to you , the problem was when the post didn't load yet , I changed it to just render when it loaded and it's working fine now – ManuC12 May 09 '20 at 14:13

0 Answers0