rsnext/packages/next/pages/_app.tsx
Balázs Orbán 8bc587aa30
feat(ts): expose AppType (#40391)
An alternative solution to #40371

Ref: #38867, https://github.com/t3-oss/create-t3-app/issues/412,
https://github.com/t3-oss/create-t3-app/pull/414

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-09-09 13:32:58 -07:00

44 lines
1.1 KiB
TypeScript

import React from 'react'
import {
loadGetInitialProps,
AppContextType,
AppInitialProps,
AppPropsType,
NextWebVitalsMetric,
AppType,
} from '../shared/lib/utils'
import type { Router } from '../client/router'
export { AppInitialProps, AppType }
export { NextWebVitalsMetric }
export type AppContext = AppContextType<Router>
export type AppProps<P = {}> = AppPropsType<Router, P>
/**
* `App` component is used for initialize of pages. It allows for overwriting and full control of the `page` initialization.
* This allows for keeping state between navigation, custom error handling, injecting additional data.
*/
async function appGetInitialProps({
Component,
ctx,
}: AppContext): Promise<AppInitialProps> {
const pageProps = await loadGetInitialProps(Component, ctx)
return { pageProps }
}
export default class App<P = {}, CP = {}, S = {}> extends React.Component<
P & AppProps<CP>,
S
> {
static origGetInitialProps = appGetInitialProps
static getInitialProps = appGetInitialProps
render() {
const { Component, pageProps } = this.props as AppProps<CP>
return <Component {...pageProps} />
}
}