Skip to content

Commit 6c33b88

Browse files
authored
Merge pull request #3 from akai-cn/feat-renderDom
feat: ctx.renderdom returns the HTML string assembled during page server rendering or client rendering
2 parents c60ab2b + edabc1b commit 6c33b88

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
lib
33
yarn.lock
4-
package-lock.json
4+
package-lock.json
5+
.DS_Store

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@umajs/plugin-react-ssr",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "In umajs, React is used to develop the plug-in of spa and MPa, which supports server-side rendering and client-side rendering",
55
"author": "zunyi_zjj@163.com",
66
"license": "MIT",

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ try {
8585
console.error(error);
8686
}
8787

88-
const renderView = async (ctx:IContext, viewName:string, initProps?:any, options?:TviewOptions) => {
88+
const renderDom = async (ctx:IContext, viewName:string, initProps?:any, options?:TviewOptions) => {
8989
const mergeProps = Object.assign(ctx.state || {}, initProps);
9090
let html = await SrejsInstance.render(ctx, viewName, mergeProps, options);
9191

@@ -108,6 +108,12 @@ const renderView = async (ctx:IContext, viewName:string, initProps?:any, options
108108
html = await engine.render(html, state);
109109
}
110110

111+
return html;
112+
};
113+
114+
const renderView = async (ctx: IContext, viewName: string, initProps?: any, options?: TviewOptions) => {
115+
const html = await renderDom(ctx, viewName, initProps, options);
116+
111117
ctx.type = 'text/html';
112118
ctx.body = html;
113119
};
@@ -137,6 +143,9 @@ export default (): TPlugin => ({
137143
async react(viewName:string, initProps?:any, options?:TviewOptions) {
138144
await renderView(this, viewName, initProps, options);
139145
},
146+
async reactDom(viewName:string, initProps?:any, options?:TviewOptions): Promise<string> {
147+
return await renderDom(this, viewName, initProps, options);
148+
},
140149
},
141150

142151
});

0 commit comments

Comments
 (0)