Last active
September 25, 2017 18:33
-
-
Save maxbeatty/4867d774315c6c765ad9bc081328ee57 to your computer and use it in GitHub Desktop.
Trying to pass a React component in `getInitialProps` to a higher order component in next.js
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"; | |
export default function MainLayout(Child) { | |
return class MainLayoutComponent extends React.Component { | |
static getInitialProps(context) { | |
return Child.getInitialProps(context); | |
} | |
render() { | |
return <div> | |
{this.props.withMainThing} | |
<Child {...this.props} /> | |
</div> | |
} | |
} | |
} | |
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 withMain from "./hoc"; | |
class Page extends Component { | |
static getInitialProps() { | |
return { | |
withMainThing: <h1>hello</h1> | |
}; | |
} | |
render() { | |
return <p>world</p> | |
} | |
} | |
export default withMain(Page); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment