Last active
August 10, 2017 06:51
-
-
Save faceyspacey/99fe879385ed854e3e8960ff386b5c5f to your computer and use it in GitHub Desktop.
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
import React from 'react' | |
import ReactDOM from 'react-dom/server' | |
import { Provider } from 'react-redux' | |
import configureStore from './configureStore' | |
import App from '../src/components/App' | |
export default () => async (req, res, next) => { | |
const store = await configureStore(req, res) | |
const app = <Provider store={store}><App /></Provider> | |
const appString = ReactDOM.renderToString(app) | |
const stateJson = JSON.stringify(store.getState()) | |
return res.send( | |
`<!doctype html> | |
<html> | |
<body> | |
<script>window.REDUX_STATE = ${stateJson}</script> | |
<div id="root">${appString}</div> | |
<script src="/static/main.js></script> | |
</body> | |
</html>` | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment