12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import App, { Container } 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 (
- <Container>
- <ApolloProvider client={apollo}>
- <Page>
- <Component {...pageProps} />
- </Page>
- </ApolloProvider>
- </Container >
- )
- }
- }
- export default withApollo(MyApp)
|