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.

Empty array is changing to empty object on rehydrate

See original GitHub issue
const initialState = [];

export default function(state = initialState, action) {
  switch (action.type) {
  case constants.UPDATE_QUESTIONS:
    return action.questions;
  }
  return state;
}

To test I deleted the app and reinstalled and started the app. The questions state started as [] and did not change. I restarted the app and then:

Before rehydrate: image

After rehydrate: image

redux-persist: 3.5.0

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
rosmcmahoncommented, Aug 5, 2020

2020, this is still occurring when root is a solo array. I have a nested persist root it overwrites my initialState = [] with an object containing {_persist… rehydrated… }

0reactions
romulororizcommented, Aug 8, 2022

I had to change my structure to:

initialState = { data: [ … ] }

now it works the way it’s supposed to

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux Persist state is empty after rehydration - Stack Overflow
I'm facing a strange issue. The rehydration worked in my app until I switched to remote dev tools that ...
Read more >
empty - Manual - PHP
When using empty() on inaccessible object properties, the __isset() ... I normally count() an array, so I wanted to see how empty() would...
Read more >
Array.prototype.pop() - JavaScript - MDN Web Docs
The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
Read more >
Usage Guide - Redux Toolkit
Importing or creating the root reducer function; Setting up middleware ... Immutable update logic, like spreading objects or copying arrays, ...
Read more >
Advanced Usage - styled-components
... Tagged Template Literals, Server-Side Rendering and Style Objects. ... or an empty string (""), which means you're free to use short-circuit evaluation ......
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