import React from 'react'

const wrapWithContext = (context, contextTypes, children) => {
  const wrapperWithContext = React.createClass({
    childContextTypes: contextTypes,
    getChildContext() {
      return context
    },
    render() {
      return children
    }
  })
  return React.createElement(wrapperWithContext)
}

export default wrapWithContext

import React from 'react'

const wrapWithContext = (context, contextTypes, children) => {
  class WrapperWithContext extends React.Component {
    getChildContext = () => context
    render = () => children
  }
  WrapperWithContext.childContextTypes = contextTypes

  return React.createElement(WrapperWithContext)
}

export default wrapWithContext

Refactor wrapWithContext: no React.createClass