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();
});
}

View File

@@ -5,7 +5,7 @@ import { StaticRouter } from 'react-router-dom';
import { replace } from 'react-router-redux';
import { createMemoryHistory } from 'history';
import { createServerRenderer, RenderResult } from 'aspnet-prerendering';
import routes from './routes';
import { routes } from './routes';
import configureStore from './configureStore';
export default createServerRenderer(params => {

View File

@@ -5,13 +5,8 @@ import Home from './components/Home';
import FetchData from './components/FetchData';
import Counter from './components/Counter';
export default <Layout>
export const routes = <Layout>
<Route exact path='/' component={ Home } />
<Route path='/counter' component={ Counter } />
<Route path='/fetchdata/:startDateIndex?' component={ FetchData } />
</Layout>;
// Enable Hot Module Replacement (HMR)
if (module.hot) {
module.hot.accept();
}