Last active
June 25, 2017 15:50
-
-
Save gregberge/2309c54e446102a457a48f90dccef456 to your computer and use it in GitHub Desktop.
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 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