You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
2.2 KiB
43 lines
2.2 KiB
8 years ago
|
---
|
||
|
id: react-dom-node-stream
|
||
|
title: ReactDOMNodeStream
|
||
|
layout: docs
|
||
|
category: Reference
|
||
|
permalink: docs/react-dom-node-stream.html
|
||
|
---
|
||
|
|
||
|
If you use ES6 with npm, you can write `import ReactDOMNodeStream from 'react-dom/node-stream'`. If you use ES5 with npm, you can write `var ReactDOMNodeStream = require('react-dom/node-stream')`.
|
||
|
|
||
|
Unlike other packages in React, `ReactDOMNodeStream` depends on a package (`stream`) that is available in Node.js but not in the browser. For this reason, there is no `<script>` tag version of `ReactDOMNodeStream`; it is only provided as a Node.js module.
|
||
|
|
||
|
## Overview
|
||
|
|
||
|
The `ReactDOMNodeStream` object allows you to render your components in Node.js and stream the resulting markup.
|
||
|
|
||
|
- [`renderToStream()`](#rendertostream)
|
||
|
- [`renderToStaticStream()`](#rendertostaticstream)
|
||
|
|
||
|
* * *
|
||
|
|
||
|
## Reference
|
||
|
|
||
|
### `renderToStream()`
|
||
|
|
||
|
```javascript
|
||
|
ReactDOMNodeStream.renderToStream(element)
|
||
|
```
|
||
|
|
||
|
Render a React element to its initial HTML. This should only be used in Node.js; it will not work in the browser, since the browser does not support Node.js streams. React will return a [Readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) that outputs an HTML string. The HTML output by this stream will be exactly equal to what [`ReactDOMServer.renderToString`](https://facebook.github.io/react/docs/react-dom-server.html#rendertostring) would return. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.
|
||
|
|
||
|
If you call [`ReactDOM.render()`](/react/docs/react-dom.html#render) on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.
|
||
|
|
||
|
* * *
|
||
|
|
||
|
### `renderToStaticStream()`
|
||
|
|
||
|
```javascript
|
||
|
ReactDOMNodeStream.renderToStaticStream(element)
|
||
|
```
|
||
|
|
||
|
Similar to [`renderToStream`](#rendertostream), except this doesn't create extra DOM attributes such as `data-reactid`, that React uses internally. This is useful if you want to use React as a simple static page generator, as stripping away the extra attributes can save lots of bytes.
|