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 by Example Building the Application Pending Name Submission Feature

Cynthia Norwood
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Cynthia Norwood
Front End Web Development Techdegree Graduate 15,202 Points

Sometimes we add "state" and sometimes we don't why is that?

Sometimes we add "state" and sometimes we don't like this code here. <GuestList guests={this.state.guests} toggleConfirmationAt={this.toggleConfirmationAt} toggleEditingAt={this.toggleEditingAt} setNameAt={this.setNameAt} isFiltered={this.state.isFiltered} removeGuestAt={this.removeGuestAt} pendingGuest={this.state.pendingGuest} />

So for pendingGuest= .... we added state but not for removeGuestAt above it??? Why is that ?

3 Answers

Jordan Wren
Jordan Wren
30,938 Points

We add state in this case because we declared a state element in the App to hold all of the properties the app may render. When we type in text in the "Invite Someone" form, in order for the PendingGuest component to know what the name of the pending guest is we need to pass it the pendingGuest property declared in the state element. removeGuestAt is not declared in the state element and is its own function, which is why we do not use this.state for it.

Zaberca David
Zaberca David
2,964 Points

For anyone that may still have this question. The simple reason is that the functions are not inside 'state'. If you look at where they are declared, 'this.toggleEditingAt' is declared at class level (inside 'App' ). On the other hand, 'this.state.pendingGuest' is declared inside 'state' object, and 'state' is declared at class level (inside 'App').