Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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