Last active
May 29, 2017 05:17
-
-
Save emilong/9f457c033919a8e2e8076e4cd9cc40de to your computer and use it in GitHub Desktop.
Configuring preloaded state to save after each action on the store
This file contains hidden or 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 { 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