Created
January 7, 2016 18:37
-
-
Save dstevensio/5340e61d9f740d905ec3 to your computer and use it in GitHub Desktop.
Binding in React with React.Component use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this._myHandlerFunc = this._myHandlerFunc.bind(this); | |
} | |
_myHandlerFunc() { | |
// do something | |
} | |
render() { | |
return <p onClick={this._myHandlerFunc}>that's like your opinion, man</p>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could also try _myHandlerFunc = ()=> {
// do something
}
And then you don't need to remember to add that binding to the constructor