Last active
November 20, 2015 09:07
-
-
Save peterlazar1993/462100ee976c5b552b2f to your computer and use it in GitHub Desktop.
React HelloWorld with state and user interaction ES6
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 HelloWorld extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {clicks: 0}; | |
} | |
incrementClick() { | |
this.setState({ | |
clicks: this.state.clicks + 1 | |
}); | |
} | |
render() { | |
return ( | |
<div> | |
Hello, World! I am {this.props.name} | |
<span onClick={(e) => {this.incrementClick(e)}}> | |
+{this.state.clicks} | |
</span> | |
</div> | |
); | |
} | |
}; | |
React.render(<HelloWorld name="React"/>, document.getElementById('container-1')); | |
React.render(<HelloWorld name="React Native"/>, document.getElementById('container-2')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment