Home > Net >  how can I add unique key prop in each child in a list on react?
how can I add unique key prop in each child in a list on react?

Time:12-06

I keep getting this error

I am trying to solve this warning.

CodePudding user response:

add key attribute with a unique identifier as the value

<li key={movies.id} .... // 

CodePudding user response:

If movies don't have an id and you just want to get rid of the warning, you can use the second argument of the map function, which returns the index:

movieDB[movie].map((movies, index) => {
  <li className='items' key={index}>
    ...
  </li>
})

CodePudding user response:

I think that every movie name is unique, so you can just

<li classname='items' key={movies.name}>
  • Related