Skip to content

Instantly share code, notes, and snippets.

@astrotim
Created July 25, 2017 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrotim/b8ab782c2d1c0e707b599dbb489100b8 to your computer and use it in GitHub Desktop.
Save astrotim/b8ab782c2d1c0e707b599dbb489100b8 to your computer and use it in GitHub Desktop.
The application file used by the Webpack production build
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import { StaticRouter as Router } from 'react-router-dom';
import App from './App';
import HTML from './HTML';
// static site generator
export default function render(locals, callback) {
const context = {};
const reactApp = {
__html: ReactDOMServer.renderToString(
<Router location={locals.path} context={context}>
<App />
</Router>
)
};
const html = ReactDOMServer.renderToStaticMarkup(
<HTML reactApp={reactApp} />
);
callback(null, '<!DOCTYPE html>' + html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment