Created
September 21, 2016 11:44
-
-
Save bogdanjsx/4758d101ac5b151a980b1a43ef7d68c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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