Skip to content

Instantly share code, notes, and snippets.

@dong-qian
Created February 12, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dong-qian/5209154de4070ee68f5078c0c1d508a2 to your computer and use it in GitHub Desktop.
Save dong-qian/5209154de4070ee68f5078c0c1d508a2 to your computer and use it in GitHub Desktop.
HRM + create-react-app + redux
// index.js
ReactDOM.render(<App /> , document.getElementById('root'))
if (module.hot) {
module.hot.accept('./App', () => {
ReactDOM.render(<App />, document.getElementById('root'))
})
}
// store.js
import { createStore } from 'redux'
import rootReducer from './reducers'
const configureStore = () => {
const store = createStore(rootReducer)
if (process.env.NODE_ENV !== "production") {
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(rootReducer)
})
}
}
return store
}
export default configureStore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment