Skip to content

Instantly share code, notes, and snippets.

@quentin-sommer
Created June 11, 2017 08:42
Show Gist options
  • Save quentin-sommer/b1379caadf2431349ce723567722e642 to your computer and use it in GitHub Desktop.
Save quentin-sommer/b1379caadf2431349ce723567722e642 to your computer and use it in GitHub Desktop.
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