Skip to content

Instantly share code, notes, and snippets.

@peterlazar1993
Last active November 20, 2015 09:07
Show Gist options
  • Save peterlazar1993/462100ee976c5b552b2f to your computer and use it in GitHub Desktop.
Save peterlazar1993/462100ee976c5b552b2f to your computer and use it in GitHub Desktop.
React HelloWorld with state and user interaction ES6
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)}}>&nbsp;
+{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