1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/errors/get-initial-props-as-an-instance-method.md
Tim Neutkens 0dd2b2aa74
Add warning for broken popstate (#5000)
* Add warning for undefined url and as coming from popstate

* Use consistent url

* Fix err.sh link in test

* Rename `inital` => `initial`
2018-08-24 12:30:27 +02:00

40 lines
678 B
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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 {
static getInitialProps () {
return {}
}
render () {
return 'foo'
}
}
```
or
```js
const YourEntryComponent = function () {
return 'foo'
}
YourEntryComponent.getInitialProps = () => {
return {}
}
export default YourEntryComponent
```
### Useful Links
- [Fetching data and component lifecycle](https://github.com/zeit/next.js#fetching-data-and-component-lifecycle)