Skip to content

Instantly share code, notes, and snippets.

@bmamouri
Last active June 7, 2016 01:40
Show Gist options
  • Save bmamouri/aaaf642b252208f6febde8c80b425ae4 to your computer and use it in GitHub Desktop.
Save bmamouri/aaaf642b252208f6febde8c80b425ae4 to your computer and use it in GitHub Desktop.
Minimal Server Rendering with ReacJS
import {renderToString} from 'react/lib/ReactDOMServer'
import {RouterContext} from 'react-router'
import {Provider} from 'react-redux'
export default (req, res) => {
const componentHTML = renderToString(
<Provider store={store}>
<RouterContext {...renderProps} />
</Provider>)
const html = `<!DOCTYPE html>
<html>
<head>
<title>ComeHome</title>
<link rel="shortcut icon" href="/favicon.ico">
</head>
<body>
<div id="main">${componentHTML}</div>
</body>
</html>`
res.send(html)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment