Created
October 29, 2018 16:20
-
-
Save tubalmartin/dd1cec99a7dc087e393ff8e0578e3a59 to your computer and use it in GitHub Desktop.
renderToNodeStream render function snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ReactDOMServer = require('react-dom/server'); | |
const render = (reactComponent) => { | |
return new Promise((resolve, reject) => { | |
const body = []; | |
const bodyStream = ReactDOMServer.renderToNodeStream(reactComponent); | |
bodyStream.on('data', (chunk) => { | |
body.push(chunk.toString()); | |
}); | |
bodyStream.on('error', (err) => { | |
reject(err); | |
}); | |
bodyStream.on('end', () => { | |
resolve(body.join('')); | |
}); | |
}); | |
}; | |
export default render; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment