import React from 'react'; class Toggle extends React.Component { state = { name: 'Hello dad' }; render() { return ( <button onClick={ this._handleButtonClick }> Greet Dad </button> ); } _handleButtonClick = () => { console.log(`Message: ${ this.state.name }`); } }
Home
/
Snippets
/
How to Bind Event Handlers in React JS Component by Avoiding Constructor Declaration
How to Bind Event Handlers in React JS Component by Avoiding Constructor Declaration
224
2 years ago
0 comments
To bind event handlers in React JS component you can easily define arrow functions, by making use of this method you will be accessing the same context in the component.
Topics:
Frontend
Resource
Average
Average
Support Us
If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️
Leave a reply