Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created January 26, 2015 12:14
Show Gist options
  • Save roman01la/39545dae9843017e1c8e to your computer and use it in GitHub Desktop.
Save roman01la/39545dae9843017e1c8e to your computer and use it in GitHub Desktop.
How to avoid storing application data within controller-view.
import React from 'react';
import AppActions from './actions';
import ItemsStore from './items-store';
let List = React.createClass({
componentDidMount() {
ItemsStore.addChangeListener(this.forceUpdate.bind(this));
},
componentWillUnmount() {
ItemsStore.removeChangeListener(this.forceUpdate.bind(this));
},
render() {
let list = ItemsStore.getState().items
.map((item, index) => <li key={index}>{item}</li>);
return (
<ul>{list}</ul>
);
}
});
React.render(<List />, document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment