Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Basics (2018) Introducing Props Setting and Using Props

Why is the Array iterated in const App(){} not in const Player(){} ?

My struggle atm is understanding why the array is iterated in the App Component, rather than the Player Component. If the Player component is responsible for displaying the names & scores, should it not also loop through the array?

1 Answer

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hey moises hernandez , the Player component represents a single player. So you wouldn't want to loop over all the players' data directly in the Player component. And all the players' data is in App.js. So to make good use of the concept of reusable components, in App.js, you loop over the player data, and pass info from each player to multiple instances of the singular reusable Player component. Hope that helps. :thumbsup:

Thanks Robert - yeah that makes sense. I hadn't realised that the Player component was only for a single player. I thought >1 players could be passed into it by looping the array inside it. Thanks for the explanation.