Skip to content

Instantly share code, notes, and snippets.

@gregberge
Last active June 25, 2017 15:50
Show Gist options
  • Save gregberge/2309c54e446102a457a48f90dccef456 to your computer and use it in GitHub Desktop.
Save gregberge/2309c54e446102a457a48f90dccef456 to your computer and use it in GitHub Desktop.
import React from 'react'
import { renderToString } from 'react-dom/server'
import { StaticRouter } from 'react-router'
import { getLoadableState } from 'loadable-components/server'
import App from './App'
const app = (
<StaticRouter>
<App />
</StaticRouter>
)
// Extract loadable state (component ids) from application tree
getLoadableState(app).then(loadableState => {
const html = renderToString(<YourApp />)
// Insert style tag containing state transfered to client
const page = `
<!doctype html>
<html>
<head></head>
<body>
<div id="main">${html}</div>
${loadableState.getScriptTag()}
</body>
</html>
`
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment