/
githubmirror
/
next.js
Обзор
Документация
Войти
/
githubmirror
/
next.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
canary
errors/get-initial-props-as-an-instance-method.mdx
41 строка
729 B
Jam Balaya
docs: fix code block language in error pages (#72943)
19 ноя 2024, 10:56
Не верифицирован
19 ноя 2024, 10:56
20dc573
Код
Авторство
О чём код?
--- 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)