Skip to content

Commit cf2f7f2

Browse files
author
David Zukowski
committed
feat(AppContainer): move root component definition to own file
1 parent a1dd09e commit cf2f7f2

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

src/containers/AppContainer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { PropTypes } from 'react'
2+
import { Router } from 'react-router'
3+
import { Provider } from 'react-redux'
4+
5+
export class AppContainer extends React.Component {
6+
static propTypes = {
7+
history: PropTypes.object.isRequired,
8+
routes: PropTypes.object.isRequired,
9+
routerKey: PropTypes.number,
10+
store: PropTypes.object.isRequired
11+
}
12+
13+
render () {
14+
const { history, routes, routerKey, store } = this.props
15+
16+
return (
17+
<Provider store={store}>
18+
<div style={{ height: '100%' }}>
19+
<Router history={history} children={routes} key={routerKey} />
20+
</div>
21+
</Provider>
22+
)
23+
}
24+
}
25+
26+
export default AppContainer

src/main.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33
import createBrowserHistory from 'history/lib/createBrowserHistory'
4-
import { Router, useRouterHistory } from 'react-router'
4+
import { useRouterHistory } from 'react-router'
55
import { syncHistoryWithStore } from 'react-router-redux'
66
import createStore from './store/createStore'
7-
import { Provider } from 'react-redux'
7+
import AppContainer from './containers/AppContainer'
88

99
// ========================================================
1010
// Browser History Setup
@@ -17,7 +17,7 @@ const browserHistory = useRouterHistory(createBrowserHistory)({
1717
// Store and History Instantiation
1818
// ========================================================
1919
// Create redux store and sync with react-router-redux. We have installed the
20-
// react-router-redux reducer under the key "router" in src/routes/index.js,
20+
// react-router-redux reducer under the routerKey "router" in src/routes/index.js,
2121
// so we need to provide a custom `selectLocationState` to inform
2222
// react-router-redux of its location.
2323
const initialState = window.___INITIAL_STATE__
@@ -40,16 +40,18 @@ if (__DEBUG__) {
4040
// ========================================================
4141
const MOUNT_NODE = document.getElementById('root')
4242

43-
let render = (key = null) => {
43+
let render = (routerKey = null) => {
4444
const routes = require('./routes/index').default(store)
45-
const App = (
46-
<Provider store={store}>
47-
<div style={{ height: '100%' }}>
48-
<Router history={history} children={routes} key={key} />
49-
</div>
50-
</Provider>
45+
46+
ReactDOM.render(
47+
<AppContainer
48+
store={store}
49+
history={history}
50+
routes={routes}
51+
routerKey={routerKey}
52+
/>,
53+
MOUNT_NODE
5154
)
52-
ReactDOM.render(App, MOUNT_NODE)
5355
}
5456

5557
// Enable HMR and catch runtime errors in RedBox

0 commit comments

Comments
 (0)