We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 80a205e + e547b70 commit a3f5b96Copy full SHA for a3f5b96
patterns/22.event-handlers.md
@@ -75,3 +75,22 @@ Arrow functions auto binds the function with `this`.
75
76
Facebook by the way recommend the same technique while dealing with functions that need the context of the same component.
77
The binding in the constructor may be also useful if we pass callbacks down the tree.
78
+
79
+A short hand example using arrow functions and avoid having to use the constructor:
80
81
+```javascript
82
+class Switcher extends React.Component {
83
+ state = { name: 'React in patterns' };
84
85
+ render() {
86
+ return (
87
+ <button onClick={ this._handleButtonClick }>
88
+ click me
89
+ </button>
90
+ );
91
+ }
92
+ _handleButtonClick = () => {
93
+ console.log(`Button is clicked inside ${ this.state.name }`);
94
95
+}
96
+```
0 commit comments