forked from gpbl/isomorphic500
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
45 lines (32 loc) · 1.07 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint no-console: 0 */
import React from "react";
import IntlUtils from "./utils/IntlUtils";
// Add promise support for browser not supporting it
import es6Promise from "es6-promise";
es6Promise.polyfill();
window.debug = require("debug");
const debug = window.debug("isomorphic500");
const mountNode = document.getElementById("content");
const dehydratedState = window.__INITIAL_STATE__;
function renderApp() {
const app = require("./app");
debug("Rehydrating state...", dehydratedState);
app.rehydrate(dehydratedState, (err, context) => {
if (err) {
throw err;
}
debug("State has been rehydrated");
const Root = app.getComponent();
React.render(<Root context={ context.getComponentContext() } />, mountNode, () => {
debug("Root component has been mounted");
});
});
}
// Load the Intl polyfill and required locale data
const locale = document.documentElement.getAttribute("lang");
IntlUtils.loadIntlPolyfill(locale)
.then(IntlUtils.loadLocaleData.bind(null, locale))
.then(renderApp)
.catch(err => {
console.error(err);
});