Skip to content
Advertisement

replace this.function.bind(this) for function component

I have a class component that looks like this:

JavaScript

I want to modify it into a functional component. However, I am unable to figure out how to accurately modify this part: onClick={this.addCoord.bind(this)}

because currently if I use onClick={props.addCoord()}, I would get errors like these upon using it:

TypeError: Cannot read property ‘x’ of undefined

JavaScript

Advertisement

Answer

Change your onClick

from this

JavaScript

to this

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement