Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created May 14, 2015 03:02
Show Gist options
  • Save karlbright/1a3e0fb5a6feba381485 to your computer and use it in GitHub Desktop.
Save karlbright/1a3e0fb5a6feba381485 to your computer and use it in GitHub Desktop.
var React = require.requireActual('react')
var assign = require.requireActual('object-assign')
function stubContext(Component, context, props) {
var _component = Component
var _context = context
var _props = props
var _contextTypes = {}
Object.keys(_context).forEach((key) => {
_contextTypes[key] = React.PropTypes.any
})
var ContextWrappedComponent = React.createClass({
childContextTypes: _contextTypes,
getChildContext: function() {
return _context
},
render: function() {
return <Component {...props} />
}
})
ContextWrappedComponent.withProps = function(props) {
return stubContext(_component, _context, assign({}, _props, props))
}
return ContextWrappedComponent
}
module.exports = stubContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment