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 Use Props to Create Reusable Components

Routine Poutine
Routine Poutine
26,050 Points

Why does the component tree put specific data before general data? Why is App.js more specific than its child component?

Hi,

I'm confused. I am thinking the most specific information should come last, emerging through the parent component. At least it feels counterintuitive to have App.js with all the specifics, and its child component with the more abstract and reusable material.

I know I am wrong about this, but just need help understanding why.

1 Answer

Bader Alsabah
Bader Alsabah
4,738 Points

I don't think you're necessarily wrong. You can look at any "tree" from root-to-stem or stem-to-root.

In the case of my limited understanding of React components - the reason you're passing the info to the "parent" App.js is because you need a way to pass it down to its children. If the children were stand alone you could pass the "parameters" to the children directly. Because App.js contains nested components you can think of it as a big function that you'e passing a large object to - and that function - App.js is handling distributing the arguments to all its sub-components.

Also, I think App.js was a last minute wrapper structure. So, in general you build small re-usable components and then pick the ones you need and wrap them around a larger container (in our case it was App.js). In my mind I thought of the <Player/> and <Counter/> components as lego pieces and App.js as the finished Lego toy - which contains as many <Player/> and <Counter/> pieces as needed.

Hopefully this didn't further confuse you! ;p