Last active
June 7, 2016 01:40
-
-
Save bmamouri/aaaf642b252208f6febde8c80b425ae4 to your computer and use it in GitHub Desktop.
Minimal Server Rendering with ReacJS
This file contains 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
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