Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Missing "key" prop for element in iterator react/jsx-key

Error: Missing "key" prop for element in iterator react/jsx-key info - Need to disable some ESLint rules?

return (
<div>
  <div>
    <BreadcrumbBlogs />
  </div>
  <div className={styles.container}>
    <div className={styles.blogblock}>
      {newsposts.slice(0, 6).map((post) => (
        <div className={styles.blogcontent} key={post.id}>
          <Image
            src={post.jetpack_featured_media_url}
            width={600}
            height={400}
            alt="thumbnail"
          ></Image>
          <Link href={`${post.id}`} className={styles.blogcolumn}>
            <div
              className={styles.blogtitile}
              dangerouslySetInnerHTML={{ __html: post.title.rendered }}
            ></div>
          </Link>
        </div>
      ))}
    </div>
  </div>
</div>

);

Screenshot

like image 907
beginner Avatar asked Oct 25 '25 10:10

beginner


1 Answers

In React, when you want to create multiple components, you have to provide a "key" for every child component, and that key has to be a unique value.

So, in order to solve that problem, add the key prop to the div

<div className={styles.blogcontent} key={post.id}>

In case you don't have an id, you can use anything that is unique (like the array index for example).

like image 149
Geisson Avatar answered Oct 28 '25 03:10

Geisson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!