提交 37ee8fc9 编写于 作者: T Tim Neutkens 提交者: Joe Haddad

Update _app documentation to reflect no longer needing next/app (#9268)

* Update _app documentation to reflect no longer needing next/app

* Remove lint-staged
上级 e09eb8d4
...@@ -1533,33 +1533,26 @@ Next.js uses the `App` component to initialize pages. You can override it and co ...@@ -1533,33 +1533,26 @@ Next.js uses the `App` component to initialize pages. You can override it and co
- Persisting layout between page changes - Persisting layout between page changes
- Keeping state when navigating pages - Keeping state when navigating pages
- Custom error handling using `componentDidCatch`
- Inject additional data into pages (for example by processing GraphQL queries) - Inject additional data into pages (for example by processing GraphQL queries)
To override, create the `./pages/_app.js` file and override the App class as shown below: To override, create the `./pages/_app.js` file and override the App class as shown below:
```js ```js
import React from 'react' function MyApp({ Component, pageProps }) {
import App from 'next/app' return <Component {...pageProps} />
}
class MyApp extends App {
// Only uncomment this method if you have blocking data requirements for // Only uncomment this method if you have blocking data requirements for
// every single page in your application. This disables the ability to // every single page in your application. This disables the ability to
// perform automatic static optimization, causing every page in your app to // perform automatic static optimization, causing every page in your app to
// be server-side rendered. // be server-side rendered.
// //
// static async getInitialProps(appContext) { // MyApp.getInitialProps = async (appContext) => {
// // calls page's `getInitialProps` and fills `appProps.pageProps` // // calls page's `getInitialProps` and fills `appProps.pageProps`
// const appProps = await App.getInitialProps(appContext); // const appProps = await App.getInitialProps(appContext);
// //
// return { ...appProps } // return { ...appProps }
// } // }
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
export default MyApp export default MyApp
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册