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 Basics 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.