Last active
June 22, 2017 14:59
-
-
Save gregberge/f8de29fc0f6abed0850a0e06532d6ba9 to your computer and use it in GitHub Desktop.
Loadable components API.
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' | |
| import { BrowserRouter } from 'react-router-dom' | |
| import { loadComponents } from 'loadable-components' | |
| import App from './App' | |
| loadComponents().then(() => { | |
| ReactDOM.render( | |
| <BrowserRouter> | |
| <App /> | |
| </BrowserRouter>, | |
| document.getElementById('main'), | |
| ) | |
| }) |
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 { asyncComponent } from 'loadable-components' | |
| export const Home = asyncComponent(() => import('client/Home')) |
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 { renderToString } from 'react-dom/server' | |
| import { getLoadableState } from 'loadable-components/server' | |
| const app = <YourApp /> | |
| getLoadableState(app).then(loadableState => { | |
| const html = renderToString(<YourApp />) | |
| const styleTag = loadableState.getStyleTag() | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment