Last active
October 10, 2018 08:03
-
-
Save quentin-sommer/b4e14e69412db4b4356a860b1584569a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* imports */ | |
const PageWrapper = Comp => | |
class extends React.Component { | |
/* | |
* We need to use args.ctx here instead of args | |
* See https://github.com/zeit/next.js#custom-document | |
*/ | |
static async getInitialProps(args) { | |
return { | |
ua: args.ctx.req | |
? args.ctx.req.headers['user-agent'] | |
: navigator.userAgent, | |
...(Comp.getInitialProps ? await Comp.getInitialProps(args) : null), | |
} | |
} | |
render() { | |
const {ua, ...props} = this.props | |
return ( | |
<UserAgentProvider ua={ua}> | |
<Comp {...props} /> | |
</UserAgentProvider> | |
) | |
} | |
} | |
class MyApp extends App { | |
render() { | |
const {Component, pageProps} = this.props | |
return ( | |
<Container> | |
<Page> | |
<Component {...pageProps} /> | |
</Page> | |
</Container> | |
) | |
} | |
} | |
// use the PageWrapper only once! | |
export default PageWrapper(MyApp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment