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
It will produce non-interactive HTML output of your React components.
31
+
它将会把 React 组件转换为非交互式 HTML 。
32
32
33
-
[See more examples below.](#usage)
33
+
[请看下方更多示例](#usage)。
34
34
35
-
#### Parameters {/*parameters*/}
35
+
#### 参数 {/*parameters*/}
36
36
37
-
*`reactNode`: A React node you want to render to HTML. For example, a JSX node like `<Page />`.
37
+
*`reactNode`:你想渲染成 HTML 的 React 节点。例如,像 `<Page />` 这样的 JSX 节点。
38
38
39
-
#### Returns {/*returns*/}
39
+
#### 返回值 {/*returns*/}
40
40
41
-
An HTML string.
41
+
一个 HTML 字符串。
42
42
43
-
#### Caveats {/*caveats*/}
43
+
#### 注意事项 {/*caveats*/}
44
44
45
-
*`renderToStaticMarkup`output cannot be hydrated.
45
+
*`renderToStaticMarkup`的输出无法进行二次渲染。
46
46
47
-
*`renderToStaticMarkup`has limited Suspense support. If a component suspends, `renderToStaticMarkup`immediately sends its fallback as HTML.
47
+
*`renderToStaticMarkup`对 Suspense 的支持有限。如果一个组件触发了 Suspense,`renderToStaticMarkup`立即将它的 fallback 作为 HTML 输出。
48
48
49
-
*`renderToStaticMarkup`works in the browser, but using it in the client code is not recommended. If you need to render a component to HTML in the browser, [get the HTML by rendering it into a DOM node.](/reference/react-dom/server/renderToString#removing-rendertostring-from-the-client-code)
49
+
*`renderToStaticMarkup`在浏览器中可以使用,但不建议在客户端代码中使用它。如果你需要在浏览器中将组件渲染成 HTML,[请把它渲染到 DOM 节点中以获取 HTML](/reference/react-dom/server/renderToString#removing-rendertostring-from-the-client-code)。
50
50
51
51
---
52
52
53
-
## Usage {/*usage*/}
53
+
## 用法 {/*usage*/}
54
54
55
-
### Rendering a non-interactive React tree as HTML to a string {/*rendering-a-non-interactive-react-tree-as-html-to-a-string*/}
55
+
### 将一个非交互式的 React 树渲染成 HTML 字符串 {/*rendering-a-non-interactive-react-tree-as-html-to-a-string*/}
56
+
``
56
57
57
-
Call`renderToStaticMarkup`to render your app to an HTML string which you can send with your server response:
58
+
调用`renderToStaticMarkup`将你的应用程序渲染为 HTML 字符串,然后将其与服务器响应一起发送:
//The route handler syntax depends on your backend framework
63
+
//路由处理程序语法取决于你的后端框架
63
64
app.use('/', (request, response) => {
64
65
consthtml=renderToStaticMarkup(<Page />);
65
66
response.send(html);
66
67
});
67
68
```
68
69
69
-
This will produce the initial non-interactive HTML output of your React components.
70
+
这将会把 React 组件转换为非交互式 HTML 。
70
71
71
72
<Pitfall>
72
73
73
-
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 [`renderToString`](/reference/react-dom/server/renderToString)on the server and [`hydrateRoot`](/reference/react-dom/client/hydrateRoot)on the client.
0 commit comments