Skip to content

Instantly share code, notes, and snippets.

@kitten
Created May 18, 2015 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitten/69ab0aafff2b2fe6cc89 to your computer and use it in GitHub Desktop.
Save kitten/69ab0aafff2b2fe6cc89 to your computer and use it in GitHub Desktop.
React ES6 Code Samples for Medium #2
import React from "react";
export default class HelloWorld extends React.Component {
constructor(props) {
super(props);
this.state = {
world: "World"
};
}
_onClick() {
this.setState({
world: "Cthulhu"
});
}
render() {
return (
<h1 onClick={this._onClick.bind(this)}>
Hello {this.state.world}!
</h1>
<ul>
{
this.props.food.map(obj => <li>{obj}</li>);
}
</ul>
);
}
}
HelloWorld.propTypes = {
food: React.PropTypes.array
};
HelloWorld.defaultProps = {
food: [ "Pizza", "Lasagna", "Sushi" ]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment