Last active
January 9, 2019 13:22
-
-
Save hellobrian/58ca75de689da79203d4070c73710860 to your computer and use it in GitHub Desktop.
HMR create-react-app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* index.js | |
*/ | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from 'App'; | |
import { Provider } from 'react-redux'; | |
import configureStore from 'state/store'; // see store.js in the gist below | |
import { BrowserRouter } from 'react-router-dom'; | |
import registerServiceWorker from 'registerServiceWorker'; | |
const store = configureStore(); | |
registerServiceWorker(); | |
const render = Component => { | |
return ReactDOM.render( | |
<Provider store={store}> | |
<BrowserRouter> | |
<Component /> | |
</BrowserRouter> | |
</Provider>, | |
document.getElementById('root') | |
); | |
}; | |
render(App); | |
if (module.hot) { | |
module.hot.accept('./App', () => { | |
const NextApp = require('./App').default; | |
render(NextApp); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* store.js | |
*/ | |
import { createStore } from 'redux'; | |
import { reducer } from 'state/nav/reducers'; // aka this is your rootReducer | |
const reduxDevTools = | |
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(); | |
const configureStore = () => { | |
const store = createStore(reducer, reduxDevTools); | |
if (process.env.NODE_ENV !== 'production') { | |
if (module.hot) { | |
module.hot.accept('./nav/reducers', () => { | |
store.replaceReducer(reducer); | |
}); | |
} | |
} | |
return store; | |
}; | |
export default configureStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment