You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/server/renderToStaticNodeStream.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: renderToStaticNodeStream
4
4
5
5
<Intro>
6
6
7
-
`renderToStaticNodeStream`renders a non-interactive React tree to a [Node.js Readable Stream.](https://nodejs.org/api/stream.html#readable-streams)
On the server, call `renderToStaticNodeStream`to get a [Node.js Readable Stream](https://nodejs.org/api/stream.html#readable-streams).
The stream will produce non-interactive HTML output of your React components.
34
+
调用此方法为 React 组件输出非交互式 HTML。
35
35
36
-
#### Parameters {/*parameters*/}
36
+
#### 参数 {/*parameters*/}
37
37
38
-
*`reactNode`: A React node you want to render to HTML. For example, a JSX element like `<Page />`.
38
+
*`reactNode`:想要渲染为 HTML 的 React 节点。比如像 `<Page />` 一样的 JSX 元素。
39
39
40
-
#### Returns {/*returns*/}
40
+
#### 返回值 {/*returns*/}
41
41
42
-
A [Node.js Readable Stream](https://nodejs.org/api/stream.html#readable-streams) that outputs an HTML string. The resulting HTML can't be hydrated on the client.
42
+
输出 HTML 字符串的 [Node.js 只读流](https://nodejs.org/api/stream.html#readable-streams),以此法输出的 HTML 不能被客户端 hydrate。
43
43
44
-
#### Caveats {/*caveats*/}
44
+
#### 注意 {/*caveats*/}
45
45
46
-
*`renderToStaticNodeStream`output cannot be hydrated.
46
+
*`renderToStaticNodeStream`的输出不能被 hydrate。
47
47
48
-
*This method will wait for all [Suspense boundaries](/reference/react/Suspense)to complete before returning any output.
*As of React 18, this method buffers all of its output, so it doesn't actually provide any streaming benefits.
50
+
*从 React 18 开始,此方法会缓冲所有输出,因此实际上它并没有提供任何流式传输的好处。
51
51
52
-
*The returned stream is a byte stream encoded in utf-8. If you need a stream in another encoding, take a look at a project like [iconv-lite](https://www.npmjs.com/package/iconv-lite), which provides transform streams for transcoding text.
### Rendering a React tree as static HTML to a Node.js Readable Stream {/*rendering-a-react-tree-as-static-html-to-a-nodejs-readable-stream*/}
58
+
### 为 Node.js 只读流将 React 树渲染为静态 HTML {/*rendering-a-react-tree-as-static-html-to-a-nodejs-readable-stream*/}
59
59
60
-
Call`renderToStaticNodeStream`to get a [Node.js Readable Stream](https://nodejs.org/api/stream.html#readable-streams) which you can pipe to your server response:
//The route handler syntax depends on your backend framework
65
+
//路由处理程序的语法取决于使用的后端框架。
66
66
app.use('/', (request, response) => {
67
67
conststream=renderToStaticNodeStream(<Page />);
68
68
stream.pipe(response);
69
69
});
70
70
```
71
71
72
-
The stream will produce the initial non-interactive HTML output of your React components.
72
+
此方法将会将 React 组件初始输出为非交互式 HTML。
73
73
74
74
<Pitfall>
75
75
76
-
This method renders **non-interactive HTML that cannot be hydrated.** This is useful if you want to use React as a simple static page generator, or if you're rendering completely static content like emails.
Interactive apps should use [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream)on the server and [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) on the client.
0 commit comments