1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import App from "next/app";
- import Page from "../components/page";
- import { ApolloProvider } from "react-apollo";
- import withApollo from "../lib/withApollo";
- /**
- * Next.js uses the `App` component to initialize pages. See:
- * https://github.com/zeit/next.js/#custom-app
- *
- * Example how to use it to style child components:
- * https://github.com/zeit/next.js/blob/canary/examples/with-app-layout/pages/_app.js
- *
- * Instead of the Layout component, we use the Page component here,
- * where we add a styled-components theme provider, and Next.js headers and metas.
- * - Using Page with layout information
- *
- * Using next-with-apollo:
- * https://github.com/lfades/next-with-apollo
- * - Wrapping MyApp in withApollo HOC
- */
- class MyApp extends App {
- static async getInitialProps({ Component, ctx }) {
- let pageProps = {};
- if (Component.getInitialProps) {
- pageProps = await Component.getInitialProps(ctx);
- }
- // Add the query object to the pageProps
- // https://github.com/wesbos/Advanced-React/blob/master/finished-application/frontend/pages/_app.js
- pageProps.query = ctx.query;
- return { pageProps };
- }
- render() {
- const { Component, apollo, pageProps } = this.props;
- return (
- <ApolloProvider client={apollo}>
- <Page>
- <Component {...pageProps} />
- </Page>
- </ApolloProvider>
- );
- }
- }
- export default withApollo(MyApp);
|