Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 24,031 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,992 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.