Skip to content

Instantly share code, notes, and snippets.

@earnubs
Created February 10, 2017 21:40
Show Gist options
  • Select an option

  • Save earnubs/c566cf6e3d85e5655907a876379c0d84 to your computer and use it in GitHub Desktop.

Select an option

Save earnubs/c566cf6e3d85e5655907a876379c0d84 to your computer and use it in GitHub Desktop.

Revisions

  1. earnubs created this gist Feb 10, 2017.
    39 changes: 39 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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;
    });
    }