_app.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import App from 'next/app'
  2. import client from '../lib/apollo'
  3. import { ApolloProvider } from '@apollo/client'
  4. import Page from '../components/page'
  5. /**
  6. * Next.js uses the `App` component to initialize pages. See:
  7. * https://github.com/zeit/next.js/#custom-app
  8. *
  9. * Using next-with-apollo:
  10. * https://github.com/lfades/next-with-apollo
  11. * - Wrapping MyApp in withApollo HOC
  12. */
  13. class MyApp extends App {
  14. static async getInitialProps ({ Component, ctx }) {
  15. let pageProps = {}
  16. if (Component.getInitialProps) {
  17. pageProps = await Component.getInitialProps(ctx)
  18. }
  19. // Add the query object to the pageProps
  20. // https://github.com/wesbos/Advanced-React/blob/master/finished-application/frontend/pages/_app.js
  21. pageProps.query = ctx.query
  22. return { pageProps }
  23. }
  24. render () {
  25. const { Component, pageProps } = this.props
  26. return (
  27. <ApolloProvider client={client}>
  28. <Page>
  29. <Component {...pageProps} />
  30. </Page>
  31. </ApolloProvider>
  32. )
  33. }
  34. }
  35. export default MyApp