forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ReactDOMStringRenderer.js
38 lines (35 loc) · 1.05 KB
/
ReactDOMStringRenderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import ReactPartialRenderer from './ReactPartialRenderer';
/**
* Render a ReactElement to its initial HTML. This should only be used on the
* server.
* See https://reactjs.org/docs/react-dom-server.html#rendertostring
*/
export function renderToString(element) {
const renderer = new ReactPartialRenderer(element, false);
try {
const markup = renderer.read(Infinity);
return markup;
} finally {
renderer.destroy();
}
}
/**
* Similar to renderToString, except this doesn't create extra DOM attributes
* such as data-react-id that React uses internally.
* See https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup
*/
export function renderToStaticMarkup(element) {
const renderer = new ReactPartialRenderer(element, true);
try {
const markup = renderer.read(Infinity);
return markup;
} finally {
renderer.destroy();
}
}