rsnext/errors/get-initial-props-as-an-instance-method.md
Rich Haines d291aa9134
Refactor data fetching API docs (#30615)
Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-01-12 08:56:51 +01:00

675 B

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