skip to Main Content

I run the dev but in console, there’s an error saying "Check the render method of Products". This is my App.

App.jsx
App.jsx

I want Products to be shown but it doesn’t appear. This is my Products.

Product.jsx
Products.jsx

2

Answers


  1. your syntax is not true. use this :

    {products.map((product) => (
       <h1 key={product.id}>{product.title}</h1>
    ))}
    
    Login or Signup to reply.
  2. enter image description here

    If your error is the same as the image above, try using key in each child (Product Element) and it’s going to work! Like as follow:

    products.map((product,index) => <h1 key={index}>{product.title}</h1>))
    

    To use index as a key is not appreciated in react so use id of product as a key. Documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search