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.