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

Jeriah Bowers
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeriah Bowers
Front End Web Development Techdegree Graduate 20,590 Points

Why in React in some cases inside the component the values of the properties are the same??

So I've seen how in some cases when adding properties to components the value of a property will be the same as the property itself. i.e. <Example removeGuest={this.removeGuest}/> Why is that?? If I'm being honest It's confusing me a little. Any help is appreciated. Thanks!

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya there! I know React can be a lot confusing when you start out learning React especially with state management and all the events and stuff like that, unlike other libraries such as Vuejs , Angular or Ember. But in general naming your methods sounds pretty easy stuff right? As easy it might sound , it can create a lots of confusion and frustration for yourself as a developer and others. Your name needs to be precise and short and explaining what it does at the same time. To me it sounds daunting a few times.

<Example removeGuest={this.removeGuest}/> 

In the above piece of code, Example component is being called and it has a property named removeGuest which as name suggests , remove guests from guests list, right? Now in React, everything thats squeezed between {} is some js code. To sum it all up, in Example component , there is a property named removeGuest which calling a method called removeGuest , which is defined somewhere. I hope it helped!

~ Ari