onclick arrow function javascript
class demo extends React.component { goToStore(event) { console.log(this) } render() { } }
Here is what the above code is Doing:
1. We’re creating a new function, goToStore, which takes an event object.
2. We’re binding the goToStore function to the current instance of the component in the constructor function.
3. We’re passing the goToStore function to the button’s onClick prop.
4. When the user clicks the button, the bound goToStore function will be invoked.