Created
June 11, 2017 08:42
-
-
Save quentin-sommer/b1379caadf2431349ce723567722e642 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
const PageWrapper = Comp => | |
class extends React.Component { | |
static async getInitialProps(args) { | |
return { | |
ua: args.req ? args.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> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment