/
index.js
49 lines (40 loc) · 1.2 KB
/
index.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
46
47
48
49
import React from 'react'
import ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import Router from './routes'
// ----------------------------------------
// Rendering
// ----------------------------------------
const mountNode = document.createElement('div')
document.body.appendChild(mountNode)
const render = NewApp =>
ReactDOM.render(
<AppContainer>
<NewApp />
</AppContainer>,
mountNode,
)
// ----------------------------------------
// HMR
// ----------------------------------------
if (__DEV__) {
// When the application source code changes, re-render the whole thing.
if (module.hot) {
module.hot.accept('./routes', () => {
// restore scroll
const { scrollLeft, scrollTop } = document.scrollingElement
ReactDOM.unmountComponentAtNode(mountNode)
try {
render(require('./routes').default)
document.scrollingElement.scrollTop = scrollTop
document.scrollingElement.scrollLeft = scrollLeft
} catch (e) {
console.error(e) // eslint-disable-line no-console
}
})
}
}
// ----------------------------------------
// Start the app
// ----------------------------------------
render(Router)