Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript documentation for _app.tsx #10345

Merged
merged 5 commits into from Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
```