Created
February 10, 2017 21:40
-
-
Save earnubs/c566cf6e3d85e5655907a876379c0d84 to your computer and use it in GitHub Desktop.
HMR with reach-hot-loader3 and webpack 2
This file contains 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
import { AppContainer } from 'react-hot-loader'; | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { createStore } from 'redux'; | |
import { render } from 'react-dom'; | |
import App from './containers/app'; | |
import reducers from './reducers'; | |
// Grab the state from a global variable injected into the server-generated HTML | |
const preloadedState = window.__PRELOADED_STATE__; | |
// Create Redux store with initial state | |
const store = (module.hot && module.hot.data && module.hot.data.store) | |
? module.hot.data.store | |
: createStore( | |
reducers, preloadedState, | |
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() | |
); | |
const contentEl = document.getElementById('content'); | |
render( | |
<Provider store={store}> | |
<AppContainer> | |
<App /> | |
</AppContainer> | |
</Provider>, | |
contentEl | |
); | |
if (module.hot) { | |
module.hot.accept(); | |
module.hot.dispose((data) => { | |
data.store = store; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment