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 Remove Items From State

Zijun Liao
Zijun Liao
13,409 Points

handleRemovePlayer binding

It seems that handleRemovePlayer is bind to App by arrow function at the beginning. And later on it is bind to Player inside onClick method, anyone explain about that and what is the this keyword refer to now?

1 Answer

Ashiwn Ashok
Ashiwn Ashok
6,774 Points

Here the "handleRemovePlayer" is bind to the "App". However, the component "Player" is able to use this function because the "App" component is passing a reference to the same function via props, which is then is being used by the player component.

Coming to what "this" stands for, it depends on the component you are referring to. For example, the "this" used inside "App" component refers to the "App" React component class itself. Similarly, the "this" inside the "Counter" component refers to the same "Counter" component itself.