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 Iterating and Rendering with map()

Conrad Casper
Conrad Casper
4,082 Points

Why do you give initialPlayers={} as a prop to the rendered App component instead of the actual App component itself?

in past examples, it seemed like you would pass down props directly from parent to child. I guess maybe this is a special case since the players array is a global variable?

2 Answers

Steve Gallant
Steve Gallant
14,943 Points

Hi Conrad, I'll take a shot, though I'm new to React as well.

The initialPlayers array contains data that may need to be changed (and probably will be later in this project). Most likely, it will be created dynamically by the app user. Because React functions must be "pure" and cannot change prop values, the data must be located outside the App function so it can be changed. When App is called with the array passed in to props, it can do it's job of iterating through the array and calling the necessary components to be rendered.

hth, Steve

Conrad, If you take a closer look he's giving it to the <App /> component, because that's where the component is being rendered. I hope it helps...