Skip to content

Instantly share code, notes, and snippets.

@earnubs
Created February 10, 2017 21:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save earnubs/c566cf6e3d85e5655907a876379c0d84 to your computer and use it in GitHub Desktop.
Save earnubs/c566cf6e3d85e5655907a876379c0d84 to your computer and use it in GitHub Desktop.
HMR with reach-hot-loader3 and webpack 2
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