Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created May 14, 2015 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlbright/55149cc8792a43b9fe4c to your computer and use it in GitHub Desktop.
Save karlbright/55149cc8792a43b9fe4c to your computer and use it in GitHub Desktop.
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