Created
May 18, 2015 22:36
-
-
Save kitten/a769e2a4c72e692b8517 to your computer and use it in GitHub Desktop.
React ES6 Code Samples for Medium #5
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
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