Update ReactReduxSpa to React Hot Loader 3, and remove Babel dependency

This commit is contained in:
Steve Sanderson
2017-05-17 21:51:13 +01:00
parent eeaf4e6590
commit 48b923fcd5
7 changed files with 31 additions and 27 deletions

View File

@@ -2,12 +2,14 @@ import './css/site.css';
import 'bootstrap';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'react-router-redux';
import { createBrowserHistory } from 'history';
import routes from './routes';
import configureStore from './configureStore';
import { ApplicationState } from './store';
import * as RoutesModule from './routes';
let routes = RoutesModule.routes;
// Create browser history to use in the Redux store
const history = createBrowserHistory();
@@ -16,11 +18,25 @@ const history = createBrowserHistory();
const initialState = (window as any).initialReduxState as ApplicationState;
const store = configureStore(history, initialState);
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
// and injects the app into a DOM element.
ReactDOM.render(
<Provider store={ store }>
<ConnectedRouter history={ history } children={ routes } />
</Provider>,
document.getElementById('react-app')
);
function renderApp() {
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
// and injects the app into a DOM element.
ReactDOM.render(
<AppContainer>
<Provider store={ store }>
<ConnectedRouter history={ history } children={ routes } />
</Provider>
</AppContainer>,
document.getElementById('react-app')
);
}
renderApp();
// Allow Hot Module Replacement
if (module.hot) {
module.hot.accept('./routes', () => {
routes = require<typeof RoutesModule>('./routes').routes;
renderApp();
});
}