Files
vercel__next.js/errors/get-initial-props-as-an-instance-method.mdx
Jam Balaya 20dc57391e docs: fix code block language in error pages (#72943)
## Summary
Update code block language in [error
pages](https://github.com/vercel/next.js/tree/canary/errors).

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
2024-11-19 07:56:55 +00:00

42 lines
729 B
Plaintext

---
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.
```jsx filename="pages/example.js"
export default class YourEntryComponent extends React.Component {
static getInitialProps() {
return {}
}
render() {
return 'foo'
}
}
```
or
```jsx 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)