Did I steal this idea? Did I read this briefly once and all of a sudden it hit me? Maybe there's a Flux implementation that does something like this? Perhaps I should understand Flux a little more? Seems legit.
// wrapper
let syncWith = function syncWith(store) {
return React.createClass({
getInitialState() {
return store.getState();
},
componentDidMount() {
return store.listen(this.onChange);
},
componentWillUnmount() {
return store.unlisten(this.onChange);
},
render() {
return(
<{this.props.elementType} className={this.props.className}>
{this.props.children}
</{this.props.elementType}>
)
}
})
};
// somewhere else...
var SyncWith = require(...);
var ProductStore = require(...);
var ...
<SyncWith store={ProductStore}>
<Component {...this.props} className="Products" elementType="div" />
</SyncWith>