Created
May 14, 2015 04:08
-
-
Save karlbright/55149cc8792a43b9fe4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var React = require.requireActual('react') | |
var assign = require.requireActual('object-assign') | |
function stubContext(Component, context) { | |
var _component = Component | |
var _context = context | |
var _contextTypes = {} | |
Object.keys(_context).forEach((key) => { | |
_contextTypes[key] = React.PropTypes.any | |
}) | |
var ContextWrapper = React.createClass({ | |
childContextTypes: _contextTypes, | |
getChildContext: function() { return _context }, | |
render: function() { return React.Children.only(this.props.children) } | |
}) | |
var ContextWrappedComponent = React.createClass({ | |
render() { | |
return <ContextWrapper><Component {...this.props} /></ContextWrapper> | |
} | |
}) | |
return ContextWrappedComponent | |
} | |
module.exports = stubContext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment