mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
[next] Add enhanceApp / enhanceComponent
https://github.com/zeit/next.js/tree/cf31021e25f8d90f91ef3f7cb4f36a46d52fc56d#customizing-renderpage https://github.com/zeit/next.js/blob/7e7be0e2e8419b28d9c562e04cba1fc52a39f086/packages/next-server/server/render.tsx#L13-L32
This commit is contained in:
Vendored
+9
-2
@@ -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