Object containing arrays not persisting
See original GitHub issueI have in my reducer an object following this structure :
const object = {
JID1: [
{
string: "stringifiedDraft",
data: {
data1: {},
data2: {},
data3: {},
},
anotherString: "JID",
},
{...},
],
JID2: [...],
JID3: [...],
}
My reducer seems to be correctly updated during runtime without any issue whatsoever.
However, when I restart my app, redux-persist
only returns me an empty object for this entry while all the other data is returned correctly.
I tried several things like persisting a dummy object like const object = { test: "test" }
and this one persists without any issue. I noticed that as soon as I have something like const object = { thing: [{ test: "test"}] }
in my reducer, only an empty object is returned.
I tried to stringify the new state before applying it to the reducer to check if there was an issue when redux-persist
stringifies my reducers states but everything went fine and my data is still here perfectly stringified so the problem does not seem to be there.
My reducers tree works this way: rootReducer -> moduleReducer -> problemReducer
Any idea ?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5
I’m working with @bockc. We solved the issue. No problem with the package, the error was on our side. We kind of forgot that the redux state was immutable 🤷♂
We’ll mark this as resolved 😃
I found solution for my problem. My initial state presents like:
const initialState: AuthState = { ..., user: { ..., entries: [], }, };
And at this case, during REHYDRATE redux persist delete array. My root reducer looks like:const rootReducer = persistReducer(persistConfig, combineReducers({ authSlice });
but when i persist reducer to the slice it works perfectlyconst rootReducer = combineReducers({ authSlice: persistReducer(persistConfig, authSlice), });
so you have to remove persistReducer from top, and wrap the slice I think this is due to nested arrays / objects