Skip to content

Instantly share code, notes, and snippets.

@kitten
Created May 18, 2015 22:36
Show Gist options
  • Save kitten/a769e2a4c72e692b8517 to your computer and use it in GitHub Desktop.
Save kitten/a769e2a4c72e692b8517 to your computer and use it in GitHub Desktop.
React ES6 Code Samples for Medium #5
import ExampleStore from "../stores/example-store.js";
import { CompatComponent } from "react-compat-component";
export default class Example extends CompatComponent {
getInitialState() {
data: ExampleStore.getList()
}
componentDidMount() {
ExampleStore.addChangeListener(this._update);
}
componentWillUnmount() {
ExampleStore.removeChangeListener(this._update);
}
_update() {
this.setState({
data: ExampleStore.getList()
});
}
render() {
return (
<ul>
{this.props.data.map(obj => <li>{obj}</li>)}
</ul>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment