Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Last active August 10, 2017 06:51
Show Gist options
  • Save faceyspacey/99fe879385ed854e3e8960ff386b5c5f to your computer and use it in GitHub Desktop.
Save faceyspacey/99fe879385ed854e3e8960ff386b5c5f to your computer and use it in GitHub Desktop.
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