Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Last active July 22, 2016 22:14
Show Gist options
  • Save jamsesso/648939220f401cb732b330f81379b03d to your computer and use it in GitHub Desktop.
Save jamsesso/648939220f401cb732b330f81379b03d to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
function withContext(key, type) {
return WrappedComponent => class ContextComponent extends Component {
static contextTypes = {
...WrappedComponent.contextTypes,
[key]: type
}
render() {
return (
<WrappedComponent {...this.context} {...this.props} />
)
}
}
}
export default withContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment