Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created March 16, 2017 12:31
Show Gist options
  • Save AlexFrazer/ea82a7e7d55fa98bbe1c80cb57f7024c to your computer and use it in GitHub Desktop.
Save AlexFrazer/ea82a7e7d55fa98bbe1c80cb57f7024c to your computer and use it in GitHub Desktop.
Promise.all([
import("react"),
import("react-dom"),
import("react-router"),
import("react-router-redux"),
import("source/store"),
import("containers/Root"),
import("source/index.css"),
import("whatwg-fetch"),
import("babel-polyfill"),
]).then(async ([
React,
{ render },
{ browserHistory },
{ syncHistoryWithStore },
{ default: configureStore },
{ default: Root },
]) => {
const target = document.getElementById("root");
const store = configureStore();
const history = syncHistoryWithStore(browserHistory, store);
const mount = async Component => {
const base = (<Component history={history} store={store} />);
try {
const { AppContainer } = await import("react-hot-loader");
render(<AppContainer>{base}</AppContainer>, target);
} catch (e) {
render(base, target);
}
};
mount(Root);
if (module.hot) {
module.hot.accept("source/containers/Root", async () => {
const { default: NextRoot } = await import("containers/Root");
mount(NextRoot);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment