JavaScript React Basics Understanding State Remove Items From State

Ewerton Luna
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ewerton Luna
Full Stack JavaScript Techdegree Graduate 23,770 Points

Why does he passes a id prop to the Player component if there's already a key prop that could be used instead?

Couldn't the Player's key prop be used as an id?

<Player 
  name={player.name}
  id={player.id}
  key={player.id.toString()}
  removePlayer={this.handleRemovePlayer}
/>
Mark Sebeck
Mark Sebeck
Treehouse Moderator 28,950 Points

Hi Ewerton. This just showed back up in my que today. Is this something you still need help with? I am not familiar with react but will look into if you are still stuck.

The key is a special string attribute help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity. They're not passed down to children as usable values.

If you try to console.log(props.key) for example, you'll see that it's undefined. Meaning {() => props.removePlayer(props.key)} won't work.