Skip to content

Instantly share code, notes, and snippets.

window.globalData = {test: 'value'}
/* 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 {
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() {
class Page extends React.Component {
static async getInitialProps(args) {
return {
ua: args.req ? args.req.headers['user-agent'] : navigator.userAgent,
}
}
render() {
const {ua} = this.props
return (
const PageWrapper = Comp => (
class extends React.Component {
static async getInitialProps(args) {
return {
ua: args.req ? args.req.headers['user-agent'] : navigator.userAgent,
lang args.req.query.language,
foo: 'bar',
/* and so on.. */
...(Comp.getInitialProps ? await Comp.getInitialProps(args) : null),
}
@quentin-sommer
quentin-sommer / next_getInitialProps_refactoring_1.js
Last active June 11, 2017 13:11
next.js getInitialProps refactoring problem
class SomePage extends React.Component {
static async getInitialProps(args) {
return {
ua: args.req ? args.req.headers['user-agent'] : navigator.userAgent,
lang args.req.query.language,
foo: 'bar',
/* and so on.. */
}
}
/* Rest of Page*/

Keybase proof

I hereby claim:

  • I am quentin-sommer on github.
  • I am sommer_q (https://keybase.io/sommer_q) on keybase.
  • I have a public key ASCbytiPgVwvY0GrBLiNYfhN2kG1rzc8Me1ZnELj5PTqtAo

To claim this, I am signing this object:

*.o
~*
*~
*.out
#*#
\#*
using System;
class Program
{
public void main(String[] args)
{
Console.WriteLine("Hello world!");
}
}