Created
March 10, 2018 16:56
-
-
Save joshburgess/925716725060c8127cb7ff8315944d3d 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
import React from 'react' | |
import hoistNonReactStatics from 'hoist-non-react-statics' | |
export default function withFlexibleRender (OriginalComponent) { | |
class ComponentWithFlexibleRender extends OriginalComponent { | |
render () { | |
const { children, render } = this.props | |
const args = { | |
props: this.props, | |
state: this.state, | |
context: this.context, | |
} | |
return children | |
? (typeof children === 'function' | |
? children(args) | |
: children | |
) | |
: (render | |
? render(args) | |
: null | |
) | |
} | |
} | |
return hoistNonReactStatics(ComponentWithFlexibleRender, OriginalComponent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment