_app.js 992 B

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