Skip to content

Instantly share code, notes, and snippets.

@0916dhkim
Created December 29, 2021 02:16
Show Gist options
  • Save 0916dhkim/3896308c7c677a59e4affe9b8037a378 to your computer and use it in GitHub Desktop.
Save 0916dhkim/3896308c7c677a59e4affe9b8037a378 to your computer and use it in GitHub Desktop.
// Original demo.
async function renderReactTree(res, props) {
await waitForWebpack();
const manifest = readFileSync(
path.resolve(__dirname, '../build/react-client-manifest.json'),
'utf8'
);
const moduleMap = JSON.parse(manifest);
pipeToNodeWritable(React.createElement(ReactApp, props), res, moduleMap);
}
// Generalized version.
async function renderReactTree(res, component, props) {
await waitForWebpack();
const manifest = readFileSync(
path.resolve(__dirname, '../build/react-client-manifest.json'),
'utf8'
);
const moduleMap = JSON.parse(manifest);
pipeToNodeWritable(React.createElement(component, props), res, moduleMap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment