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 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,214 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,940 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,965 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').