2021-06-02 17:11:03 +02:00
|
|
|
import React from 'react'
|
2019-05-30 03:19:32 +02:00
|
|
|
import {
|
|
|
|
loadGetInitialProps,
|
|
|
|
AppContextType,
|
|
|
|
AppInitialProps,
|
|
|
|
AppPropsType,
|
2020-07-03 05:36:13 +02:00
|
|
|
NextWebVitalsMetric,
|
2021-06-30 11:43:31 +02:00
|
|
|
} from '../shared/lib/utils'
|
2021-11-25 10:46:00 +01:00
|
|
|
import type { Router } from '../client/router'
|
2018-10-03 00:08:57 +02:00
|
|
|
|
2019-05-06 23:42:04 +02:00
|
|
|
export { AppInitialProps }
|
2019-04-22 19:55:03 +02:00
|
|
|
|
2020-07-03 05:36:13 +02:00
|
|
|
export { NextWebVitalsMetric }
|
|
|
|
|
2019-04-26 09:37:57 +02:00
|
|
|
export type AppContext = AppContextType<Router>
|
2019-04-22 19:55:03 +02:00
|
|
|
|
2019-04-29 18:47:40 +02:00
|
|
|
export type AppProps<P = {}> = AppPropsType<Router, P>
|
2019-04-22 19:55:03 +02:00
|
|
|
|
2019-05-23 21:31:22 +02:00
|
|
|
/**
|
|
|
|
* `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.
|
|
|
|
*/
|
2019-05-30 03:19:32 +02:00
|
|
|
async function appGetInitialProps({
|
|
|
|
Component,
|
|
|
|
ctx,
|
|
|
|
}: AppContext): Promise<AppInitialProps> {
|
2019-05-22 18:36:53 +02:00
|
|
|
const pageProps = await loadGetInitialProps(Component, ctx)
|
|
|
|
return { pageProps }
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:23:50 +02:00
|
|
|
export default class App<P = {}, CP = {}, S = {}> extends React.Component<
|
|
|
|
P & AppProps<CP>,
|
|
|
|
S
|
2019-05-30 03:19:32 +02:00
|
|
|
> {
|
2019-05-22 18:36:53 +02:00
|
|
|
static origGetInitialProps = appGetInitialProps
|
|
|
|
static getInitialProps = appGetInitialProps
|
2018-10-03 00:08:57 +02:00
|
|
|
|
2019-04-22 19:55:03 +02:00
|
|
|
render() {
|
2021-06-02 17:11:03 +02:00
|
|
|
const { Component, pageProps } = this.props as AppProps<CP>
|
2018-10-03 00:08:57 +02:00
|
|
|
|
2021-06-02 17:11:03 +02:00
|
|
|
return <Component {...pageProps} />
|
2018-10-03 00:08:57 +02:00
|
|
|
}
|
|
|
|
}
|