From c100f2732e08e64d5011bb21a11e21f49834a2ad Mon Sep 17 00:00:00 2001 From: SunLxy <1011771396@qq.com> Date: Fri, 8 Apr 2022 11:23:17 +0800 Subject: [PATCH] =?UTF-8?q?type(@kkt/react-ssr-enhanced):=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react-ssr-enhanced/src/Document.tsx | 3 +- packages/react-ssr-enhanced/src/index.ts | 2 +- packages/react-ssr-enhanced/src/interface.ts | 32 ++++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/react-ssr-enhanced/src/Document.tsx b/packages/react-ssr-enhanced/src/Document.tsx index 4bea4eb..a427876 100644 --- a/packages/react-ssr-enhanced/src/Document.tsx +++ b/packages/react-ssr-enhanced/src/Document.tsx @@ -61,7 +61,8 @@ const Document = (props: DocumentProps) => { ); } // @ts-ignore -Document.getInitialProps = async ({ assets, data, extractor, renderPage, store }) => { +Document.getInitialProps = async (props) => { + const { assets, data, extractor, renderPage, store, } = props // https://reacttraining.com/react-router/web/example/static-router // This example renders a route within a StaticRouter and populates its // staticContext, which it then prints out. In the real world you would diff --git a/packages/react-ssr-enhanced/src/index.ts b/packages/react-ssr-enhanced/src/index.ts index 081becc..35028bf 100644 --- a/packages/react-ssr-enhanced/src/index.ts +++ b/packages/react-ssr-enhanced/src/index.ts @@ -5,7 +5,7 @@ import RoutersController from './RoutersController'; import ensureReady from './ensureReady'; import render from './render'; import { loadInitialProps } from './loadInitialProps'; - +export * from "./interface" export { render, RoutersController, diff --git a/packages/react-ssr-enhanced/src/interface.ts b/packages/react-ssr-enhanced/src/interface.ts index f534351..c3a3de5 100644 --- a/packages/react-ssr-enhanced/src/interface.ts +++ b/packages/react-ssr-enhanced/src/interface.ts @@ -1,11 +1,12 @@ -import { RouteObject } from 'react-router-dom'; +import { RouteObject, PathMatch } from 'react-router-dom'; import { RematchStore, Models } from "@rematch/core" import express from 'express'; import React from "React" +import { HelmetData } from 'react-helmet'; export type ElementNewType = React.ReactNode & { load?: (v?: unknown) => Promise; - getInitialProps?: (v?: unknown) => Promise; + getInitialProps?: (v?: GetInitialProps) => Promise; name?: string; } @@ -13,14 +14,39 @@ export interface RouteNewObject extends RouteObject { element?: ElementNewType; children?: RouteNewObject[] name?: string; - load?: (v?: unknown) => Promise; + load?: (v: GetInitialProps) => Promise; } + export interface RenderProps { store: RematchStore, any>; req: express.Request; res: express.Response; assets: Record routes: RouteNewObject[] + document?: React.FC & { + getInitialProps: (props: DocinitProps) => Promise + }, + customRenderer?: (element: React.ReactElement>) => { html: string } + [k: string]: any +} + +export interface DocinitProps { + store: RematchStore, any>, + req: express.Request, + res: express.Response, + assets: Record, + data: unknown, + renderPage: () => Promise<{ helmet: HelmetData, html: string }>, + helmet: HelmetData, + match: PathMatch | null, + [k: string]: unknown +} + +export interface GetInitialProps { + store: RematchStore, any>, + req: express.Request, + res: express.Response, + match: PathMatch, [k: string]: any } \ No newline at end of file