get-initial-props-as-an-instance-method.mdx


title: 'getInitialProps was defined as an instance method'

Why This Error Occurred

getInitialProps must be a static method in order to be called by next.js.

Possible Ways to Fix It

Use the static keyword.

export default class YourEntryComponent extends React.Component {
  static getInitialProps() {
    return {}
  }

  render() {
    return 'foo'
  }
}

or

const YourEntryComponent = function () {
  return 'foo'
}

YourEntryComponent.getInitialProps = () => {
  return {}
}

export default YourEntryComponent

Rendered from the public repository vercel/next.js on GitHub; content belongs to its authors. Cached for up to an hour.

errors/get-initial-props-as-an-instance-method.mdx · vercel/next.js | Docs MD