I am new to Typscript with React and I am getting this error message on my Google console Inspect element. I checked many posts over this but unable to understand what went wrong here. Can someone help to rectify the mistake in my code?
index.js:1 Warning: Each child in a list should have a unique "key" prop.
Check the render method of
PostList
. Seein div (at PostList.tsx:19) in PostList (at pages/index.tsx:25) in div (at pages/index.tsx:21) in IndexPage (at App.tsx:68) in component (created by Context.Consumer) in Route (at App.tsx:65) in div (at App.tsx:64) in div (at App.tsx:85) in Router (created by BrowserRouter) in BrowserRouter (at App.tsx:84) in App (at src/index.tsx:8)
export default class PostList extends React.Component <Props, Post>{
renderPosts(){
const posts=Object.values (this.props.posts);
return posts.map((n)=> <div>
<h2> <Link to= {`/posts/${n._id}`}> {n.title}</Link></h2>
</div>);
}
render(){
return(
<div>
{ this.renderPosts() }
</div>
)
}
}