Skip to content

Commit

Permalink
Update _app documentation to reflect no longer needing next/app (#9268)
Browse files Browse the repository at this point in the history
* Update _app documentation to reflect no longer needing next/app

* Remove lint-staged
  • Loading branch information
timneutkens authored and Timer committed Oct 31, 2019
1 parent e09eb8d commit 37ee8fc
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1533,33 +1533,26 @@ Next.js uses the `App` component to initialize pages. You can override it and co

- Persisting layout between page changes
- Keeping state when navigating pages
- Custom error handling using `componentDidCatch`
- 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:

```js
import React from 'react'
import App from 'next/app'

class MyApp extends App {
// Only uncomment this method if you have blocking data requirements for
// every single page in your application. This disables the ability to
// perform automatic static optimization, causing every page in your app to
// be server-side rendered.
//
// static async getInitialProps(appContext) {
// // calls page's `getInitialProps` and fills `appProps.pageProps`
// const appProps = await App.getInitialProps(appContext);
//
// return { ...appProps }
// }

render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

// Only uncomment this method if you have blocking data requirements for
// every single page in your application. This disables the ability to
// perform automatic static optimization, causing every page in your app to
// be server-side rendered.
//
// MyApp.getInitialProps = async (appContext) => {
// // calls page's `getInitialProps` and fills `appProps.pageProps`
// const appProps = await App.getInitialProps(appContext);
//
// return { ...appProps }
// }

export default MyApp
```
Expand Down

0 comments on commit 37ee8fc

Please sign in to comment.