mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[next] Add enhanceApp / enhanceComponent
cf31021e25 (customizing-renderpage)7e7be0e2e8/packages/next-server/server/render.tsx (L13-L32)
This commit is contained in:
11
types/next/document.d.ts
vendored
11
types/next/document.d.ts
vendored
@@ -27,8 +27,15 @@ export type Enhancer<E extends PageProps = AnyPageProps, P extends any = E> = (
|
||||
*/
|
||||
export interface NextDocumentContext<Q extends DefaultQuery = DefaultQuery> extends NextContext<Q> {
|
||||
/** A callback that executes the actual React rendering logic (synchronously) */
|
||||
renderPage<E extends PageProps = AnyPageProps, P extends any = E>(
|
||||
enhancer?: Enhancer<E, P> // tslint:disable-line no-unnecessary-generics
|
||||
renderPage<
|
||||
E extends PageProps = AnyPageProps,
|
||||
P = E,
|
||||
EA extends PageProps = AnyPageProps,
|
||||
PA = EA,
|
||||
>(
|
||||
enhancer?:
|
||||
| Enhancer<E, P> // tslint:disable-line no-unnecessary-generics
|
||||
| { enhanceApp?: Enhancer<EA, PA>; enhanceComponent?: Enhancer<E, P> } // tslint:disable-line no-unnecessary-generics
|
||||
): RenderPageResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,20 @@ class MyDoc extends Document<WithUrlProps> {
|
||||
static async getInitialProps(ctx: NextDocumentContext) {
|
||||
const { req, renderPage } = ctx;
|
||||
|
||||
// without callback
|
||||
// without enhancer
|
||||
const _page = renderPage();
|
||||
|
||||
// with callback
|
||||
const enhancer: Enhancer<PageProps, {}> = App => props => <App />;
|
||||
const { html, head, buildManifest } = renderPage(enhancer);
|
||||
// with component enhancer
|
||||
const enhancer: Enhancer<PageProps, {}> = Component => props => <Component />;
|
||||
const _enhancedPage = renderPage(enhancer);
|
||||
|
||||
// with app and component enhancers
|
||||
const enhanceApp: Enhancer<PageProps, {}> = App => props => <App />;
|
||||
const enhanceComponent: Enhancer<PageProps, {}> = Component => props => <Component />;
|
||||
const { html, head, buildManifest } = renderPage({
|
||||
enhanceApp,
|
||||
enhanceComponent
|
||||
});
|
||||
|
||||
const initialProps = await Document.getInitialProps(ctx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user