Skip to content

Commit

Permalink
TypeScript documentation for _app.tsx (vercel#10345)
Browse files Browse the repository at this point in the history
* TypeScript documentation for _app.tsx

* Use relative URL

* Use relative URL

* Update docs/basic-features/typescript.md

Co-Authored-By: Luis Alvarez D. <luis@zeit.co>

* Update docs/basic-features/typescript.md

Co-Authored-By: Luis Alvarez D. <luis@zeit.co>

Co-authored-by: Luis Alvarez D. <luis@zeit.co>
  • Loading branch information
chibicode and Luis Alvarez D. committed Feb 11, 2020
1 parent 7d21b71 commit 72722c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/advanced-features/custom-app.md
Expand Up @@ -10,6 +10,7 @@ Next.js uses the `App` component to initialize pages. You can override it and co
- Keeping state when navigating pages
- Custom error handling using `componentDidCatch`
- Inject additional data into pages
- [Add global CSS](/docs/basic-features/built-in-css-support#adding-a-global-stylesheet)

To override the default `App`, create the file `./pages/_app.js` as shown below:

Expand Down Expand Up @@ -41,6 +42,10 @@ The `Component` prop is the active `page`, so whenever you navigate between rout

> Adding a custom `getInitialProps` in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md).
### TypeScript

If you’re using TypeScript, take a look at [our TypeScript documentation](/docs/basic-features/typescript#custom-app).

## Related

For more information on what to do next, we recommend the following sections:
Expand Down
14 changes: 14 additions & 0 deletions docs/basic-features/typescript.md
Expand Up @@ -118,3 +118,17 @@ export default (req: NextApiRequest, res: NextApiResponse<Data>) => {
res.status(200).json({ name: 'John Doe' })
}
```

## Custom `App`

If you have a [custom `App` ](/docs/advanced-features/custom-app), you can use the built-in type `AppProps`, like so:

```ts
import { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}

export default MyApp
```

0 comments on commit 72722c9

Please sign in to comment.