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) Understanding State Creating the Application State

Thomas McNish
Thomas McNish
10,893 Points

Can someone help me understand why we edited the Player component within the App component?

In the previous steps, we converted the counter component from a stateless component to a class component. Now, instead of doing the same thing for the Player component, we're converting its parent. Why didn't we make a class component out of the Player component?

2 Answers

Tyler McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tyler McDonald
Full Stack JavaScript Techdegree Graduate 16,700 Points

I believe it's because we want to change data in App component, rather than the Players component. Right now, each Player component consists of only the player's name, and their Counter component. By converting our App component to stateful, we're opening up the functionality to add and delete Player components. If we tried to do this within the Player component, we wouldn't be able to add or delete Players, but only modify a player name.

MD MONIRUZZAMAN
MD MONIRUZZAMAN
6,130 Points

Putting players array inside main state make data available to entire app.On the otherhand, counter state is not visible outside of its component. To understand better,I recommend to watch React component series