question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object containing arrays not persisting

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

7reactions
GuillaumeMunschcommented, Aug 19, 2019

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 😃

0reactions
margrudniakcommented, May 11, 2022

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 perfectly const 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving object that contains an array of objects - Stack Overflow
Let's say I have an object. And one of the characteristics of that on object is that it contains an array of objects...
Read more >
Array.prototype.find() - JavaScript - MDN Web Docs - Mozilla
The find() method returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the ...
Read more >
5. Working with Arrays and Loops - JavaScript Cookbook [Book]
An array, whether literal or object, can hold values of different data types: ... Not all array elements have to be defined when...
Read more >
Data Structures: Objects and Arrays - Eloquent JavaScript
The first index of an array is zero, not one. So the first element is retrieved with listOfNumbers[0] . Zero-based counting has a...
Read more >
Arrays - The Modern JavaScript Tutorial
Arrays. Objects allow you to store keyed collections of values. ... It is not convenient to use an object here, because it provides...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found