-5

Can't get rid of "Warning: Each child in a list should have a unique "key" prop."

 const Course = () => {

    const list = course.parts.map(parts => <li key={course.parts.id}>{parts.name} {parts.exercises}</li>)
    const exerscisesOnly = course.parts.map( x => x.exercises)
    var all = 0;

    for(var i = 0; i < exerscisesOnly.length; i++){
        all = all + exerscisesOnly[i]
    }



    const Header = (props) => {
      console.log(props)
        return (
            <div>
                <h1>{props.course}</h1>
            </div>
        )
    }

I have defined the key inside course.part.map but it doesn't want to work

Edit: This was marked as a duplicate as it should be, but I am still baffled by why my {course.parts.id} did not do the same as {parts.id}. It atleast to my eyes links to the same place.

Samuel
  • 52
  • 7
  • Welcome to Stack Overflow! Please [**search**](/search?q=%5Breact%5D+Warning%3A+Each+child+in+a+list+should+have+a+unique+"key"+prop.) before posting. More about searching [here](/help/searching). – T.J. Crowder Nov 01 '19 at 11:32
  • @Md.AbuSayed — Don't do that. "From reactjs.org/docs/lists-and-keys.html#keys: "We don’t recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state." (via T.J. Crowder) – Quentin Nov 01 '19 at 11:33