2018-08-09 19:13:44 +02:00
|
|
|
# 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
|
|
|
|
export default class YourEntryComponent extends React.Component {
|
2019-05-29 13:57:26 +02:00
|
|
|
static getInitialProps() {
|
2018-08-09 19:13:44 +02:00
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
render() {
|
2018-08-09 19:13:44 +02:00
|
|
|
return 'foo'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
```js
|
2020-05-18 21:24:37 +02:00
|
|
|
const YourEntryComponent = function () {
|
2018-08-09 19:13:44 +02:00
|
|
|
return 'foo'
|
|
|
|
}
|
|
|
|
|
|
|
|
YourEntryComponent.getInitialProps = () => {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default YourEntryComponent
|
|
|
|
```
|
|
|
|
|
|
|
|
### Useful Links
|
|
|
|
|
2022-01-12 08:56:51 +01:00
|
|
|
- [Fetching data and component lifecycle](https://nextjs.org/docs/api-reference/data-fetching/get-initial-props)
|