Skip to content

Instantly share code, notes, and snippets.

@maxbeatty
Last active September 25, 2017 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxbeatty/4867d774315c6c765ad9bc081328ee57 to your computer and use it in GitHub Desktop.
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
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>
}
}
}
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