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 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,918 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...