-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
localStorage values getting cleared when refreshing the page #14
Comments
Hi @rightaway, yes something changed; rehydration of the persisted state isn't done "auto-magically" anymore. There were a number of edge cases that led to unexpected behaviour and it felt too opinionated. You can either use the higher order reducer provided by redux-localstorage ("mergePersistedState") or handle the INIT event in your own reducer(s). Have a look at the Readme on the breaking changes branch for more info: https://github.com/elgerlambert/redux-localstorage/tree/1.0-breaking-changes |
Thank you! The deep merge fix you suggested works beautifully. |
@elgerlambert How to accomplish this merge using the current version? I am having the same issue, but I don't want to use 1.0. |
Hi @localhosted, version 0.4 performs a simple shallow merge of your persisted data by default. If your requirements are more complex (e.g. you require a deep merge or you're using immutable data structures for example) than you can pass in your own var myMergeFunction = function (initialState, persistedState) {
// custom merge logic goes here
return mergedState
}
var createPersistentStore = compose(
persistState(/*paths*/, {merge: myMergeFunction})
)(createStore) Note: There is a know issue with 0.4 which is a complication with default/initial values defined in your reducers. The problem in short is this: 0.4 takes the initialState passed in to Let me know if you're unable to solve your issue with the info above. |
I think this just started happening after upgrading to the latest redux and redux-localstorage (was using versions from a few weeks ago previously). When I refresh the page, the values I've set in localStorage get reverted back to the empty
{}
. Am I doing it wrong, or did something change?The text was updated successfully, but these errors were encountered: