Skip to content

Instantly share code, notes, and snippets.

@emilong
Last active May 29, 2017 05:17
Show Gist options
  • Save emilong/9f457c033919a8e2e8076e4cd9cc40de to your computer and use it in GitHub Desktop.
Save emilong/9f457c033919a8e2e8076e4cd9cc40de to your computer and use it in GitHub Desktop.
Configuring preloaded state to save after each action on the store
import { applyMiddleware, createStore } from "redux";
import thunk from "redux-thunk";
import reducer from "./api";
function savePreloadedState({ getState }) {
return next => action => {
const returnValue = next(action);
// just point the __PRELOADED_STATE__ at the state after this action.
window.__PRELOADED_STATE__ = getState();
// we're not modifying the state, just spying on it.
return returnValue;
};
}
const store = createStore(
reducer,
applyMiddleware(thunk, savePreloadedState)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment