Last active
November 16, 2016 04:22
-
-
Save ryanflorence/550a93226ae69f601eb0 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
class Profile extends React.Component { | |
// etc. | |
} | |
function createContainer (Component) { | |
return class extends React.Component { | |
render () { | |
return <Component {...this.props}/> | |
} | |
} | |
} | |
const Thing = createContainer(Profile, { | |
extra: 'stuff' | |
}) | |
// createContainer is a factory not a "Higher Order Component" | |
// But `Thing` is a "Higher Order Component" | |
// because it renders a Profile, but then again ... doesn't | |
// every component render another component, and therefore | |
// qualifies as a higher-order component? | |
// | |
// So does "higher order component" mean something more than | |
// "a component that renders a component", and if so, what is | |
// the strict-ish definition of higher order component? | |
// | |
// Maybe `Thing` is a HOC because it is a component created by | |
// a factory that renders another component? |
alright, i'll just get over it, bothers me that createContainer
isn't actually a component, but is called a higher order component, definitely makes more sense when using plain function components.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example using plain functions as components (0.14-master) might make it clearer why
createContainer
can be seen as a "Component" and why "Higher Order Components" are really just "Higher-order Functions" in disguise.