Export Date state then import back convert into Strings
holyman2k opened this issue · 4 comments
When export a state contains a date object, then import the same state back, the object is stored as string instead of date
I'm experiencing this issue when my dates are meant to be moment objects, but just come back as strings and then none of the state loads.
@holyman2k, @JemarJones in order the extension to handle unserializable by JSON.stringify
data (like dates, regexes, undefined, error objects, symbols and functions) just set serialize
parameter to true
:
const store = Redux.createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__({
serialize: true
}));
See Troubleshooting and API for more details.
Note that the extension implementation are completely different from the repository you were filing the issue, thus the confusion.
Oh, and here i was thinking it didn't have anything to do with the extension
const store = createStore(
appReducer,
compose(
// The logger MUST be last (other than DevTools)
applyMiddleware(routerMiddleware(browserHistory), thunk, logger),
window.devToolsExtension ? window.devToolsExtension() : f => f
)
);
Should i just do:
const store = createStore(
appReducer,
compose(
// The logger MUST be last (other than DevTools)
applyMiddleware(routerMiddleware(browserHistory), thunk, logger),
window.devToolsExtension ? window.devToolsExtension({
serialize: true
}) : f => f
)
);
?
@JemarJones yes, your snippet looks good to me. Just keep in mind that window.devToolsExtension
will be deprecated in favour of window.__REDUX_DEVTOOLS_EXTENSION__
.