Skip to content

Instantly share code, notes, and snippets.

@me-andre
Created December 22, 2015 11:52
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 me-andre/0ca8b80239cd4624e6fc to your computer and use it in GitHub Desktop.
Save me-andre/0ca8b80239cd4624e6fc to your computer and use it in GitHub Desktop.
<FluxCache store={store} propName="items" component={Component} id={this.props.routeParams.id} />
var FluxCache = React.createClass({
componentWillMount() {
this.props.store.addListener('change', this.onStoreChange);
},
componentWillUnmount() {
this.props.store.removeListener('change', this.onStoreChange);
},
onStoreChange() {
this.setState({data: this.props.store.read()});
},
render() {
var Component = this.props.component;
var props = omit(this.props, 'propName');
props[this.props.propName] = this.state.data;
return <Component {...props} />;
}
});
var Component = React.createClass({
render() {
var item = this.props.items[this.props.id];
return <div>{item.name}</div>;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment