Skip to content

Commit

Permalink
type(@kkt/react-ssr-enhanced):修改类型声明
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Apr 8, 2022
1 parent f39b2a1 commit c100f27
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/react-ssr-enhanced/src/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ssr-enhanced/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 29 additions & 3 deletions packages/react-ssr-enhanced/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
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<void>;
getInitialProps?: (v?: unknown) => Promise<void>;
getInitialProps?: (v?: GetInitialProps) => Promise<void>;
name?: string;
}

export interface RouteNewObject extends RouteObject {
element?: ElementNewType;
children?: RouteNewObject[]
name?: string;
load?: (v?: unknown) => Promise<void>;
load?: (v: GetInitialProps) => Promise<void>;
}


export interface RenderProps {
store: RematchStore<Models<any>, any>;
req: express.Request;
res: express.Response;
assets: Record<string, any>
routes: RouteNewObject[]
document?: React.FC<any> & {
getInitialProps: (props: DocinitProps) => Promise<void>
},
customRenderer?: (element: React.ReactElement<any, string | React.JSXElementConstructor<any>>) => { html: string }
[k: string]: any
}

export interface DocinitProps {
store: RematchStore<Models<any>, any>,
req: express.Request,
res: express.Response,
assets: Record<string, any>,
data: unknown,
renderPage: () => Promise<{ helmet: HelmetData, html: string }>,
helmet: HelmetData,
match: PathMatch<string> | null,
[k: string]: unknown
}

export interface GetInitialProps {
store: RematchStore<Models<any>, any>,
req: express.Request,
res: express.Response,
match: PathMatch<string>,
[k: string]: any
}

0 comments on commit c100f27

Please sign in to comment.