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.

How to save only part of deeply nested state

See original GitHub issue

How do I save only the grandchild state in config? {keys: [{parent: {child: ['grandchild']}}]} doesn’t seem to work

{
  parent: {
    child: {
      grandchild: { ... }
    }
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:9

github_iconTop GitHub Comments

3reactions
EugenAzcommented, Sep 7, 2018

Doesn’t work for me.

My store looks like this:

{
  parent: {
    child: {
      grandchild: 'string'
    }
  }
}

and configuration:

export const localStorageSyncReducer = (reducer: ActionReducer<any>): ActionReducer<any> =>
  localStorageSync({
    keys: [
      {
        parent: [
          { child: [ 'grandchild' ] }
        ]
      }
    ],
    rehydrate: true,
    storageKeySerializer: (key: string) => `store-cache.${key}`,
  })(reducer);

As a result in localStorage i see the key store-cache.parent and its value is "{}"

What do i do wrong?

2reactions
x3igh7commented, Jun 11, 2018

{keys: [{parent: [{child: ['grandchild', 'grandchild2'], 'parentProperty']}]}

Need that extra [ array after parent I think

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update nested state properties in React - Stack Overflow
Here is the Hookstate example, where the state is deeply / recursively nested in tree-like data structure. Save this answer. Show activity on...
Read more >
Why is it so difficult to modify a deeply nested state in React?
The best solution is to avoid the problem. If you have a nested state, try to flatten it. Check out three main reasons...
Read more >
Deeply Nested Objects and Redux | Pluralsight
First, came the component state and soon it was not enough to keep up with the increasing complexities of SPA (Single Page Applications)....
Read more >
Nested state | Hookstate
We can dive to the deeply nested states of primitive values and set it, like we set the name property of a task...
Read more >
Update nested properties in a State object in React | bobbyhadz
To update nested properties in a state object in React, pass a function to `setState` to get access to the current state object....
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