44d1a1cb15
This PR is part of a larger effort to migrate error messages to MDX and use App Router: https://github.com/vercel/front/pull/23459
41 lines
727 B
Text
41 lines
727 B
Text
---
|
|
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.
|
|
|
|
```js filename="pages/example.js"
|
|
export default class YourEntryComponent extends React.Component {
|
|
static getInitialProps() {
|
|
return {}
|
|
}
|
|
|
|
render() {
|
|
return 'foo'
|
|
}
|
|
}
|
|
```
|
|
|
|
or
|
|
|
|
```js filename="pages/example.js"
|
|
const YourEntryComponent = function () {
|
|
return 'foo'
|
|
}
|
|
|
|
YourEntryComponent.getInitialProps = () => {
|
|
return {}
|
|
}
|
|
|
|
export default YourEntryComponent
|
|
```
|
|
|
|
## Useful Links
|
|
|
|
- [Fetching data and component lifecycle](/docs/pages/api-reference/functions/get-initial-props)
|