Skip to content

Instantly share code, notes, and snippets.

@bogdanjsx
Created September 21, 2016 11:44
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 bogdanjsx/4758d101ac5b151a980b1a43ef7d68c2 to your computer and use it in GitHub Desktop.
Save bogdanjsx/4758d101ac5b151a980b1a43ef7d68c2 to your computer and use it in GitHub Desktop.
class ReduxProxy extends React.Component {
constructor(fixture) {
super();
this.store = createStore(fixture[fixtureStoreKey]);
}
getChildContext() {
return {
store: this.store,
};
}
render() {
// This creates a new element identical to this.props.children.
// It is needed because in older versions of React context is owner-based
// https://gist.github.com/jimfb/0eb6e61f300a8c1b2ce7
// React.cloneElement is not enough either, as it doesn't reset owner in older React versions.
const { type, props, ref } = this.props.children;
return (
React.createElement(type, _.assign(
{}, _.omit(props, fixtureStoreKey), { ref }
))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment