Created
August 14, 2018 13:59
-
-
Save ristaa/33d7d89ba343f54c793a0aab8f199c05 to your computer and use it in GitHub Desktop.
Bind in constructor - react
This file contains 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 App extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { message: "Hello World!" }; | |
this.logMessage = this.logMessage.bind(this); | |
} | |
logMessage = () => { | |
console.log(this.state.message); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<input | |
type="button" | |
value="Show message" | |
onClick={this.logMessage} | |
/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment