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.

Default value ignores/overwrites previous localStorage state

See original GitHub issue

Hey there,

I am confused by the behavior of the defaultValue prop. I would imagine that say for the key of ‘color’, setting a defaultValue of ‘red’, would only set the attribute to ‘red’ if no other value was set for color already (in localStorage in my case).

Here’s an example of what I find confusing: image

https://codesandbox.io/s/purple-morning-1z2or?file=/src/App.js

This is confusing behavior IMO. I don’t think the pre-existing localStorage keys should be clobbered by something that is named a defaultValue.

Thoughts @astoilkov ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tnrichcommented, Dec 10, 2021

Awesome thanks @astoilkov !!

1reaction
astoilkovcommented, Dec 10, 2021

Wow. That’s actually a very bad bug. I fixed it and published a new release.

Thanks, @tnrich!

Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should the state from storage override or merge with ... - GitHub
The default value is not present if a new property is added to a state that was persisted to local storage before.
Read more >
default values from initial state are loaded before store ...
I'm having trouble accessing saved data after app starts with redux-persist. The reducer initializes with data defined in my initial state. By ...
Read more >
Redux: Persisting the State to the Local Storage - Egghead.io
[00:00] I want to persist the state of the application in the localStorage using browser localStorage API. I'm going to write a function...
Read more >
Customizing the behavior of cached fields - Apollo GraphQL
The following read function returns a default value of UNKNOWN NAME for the name field of a Person type whenever a value isn't...
Read more >
Persisting Redux State to Local Storage | by Jam Creencia
Write the function that loads the state from localStorage ... create store so that it overrides the initial state specified by the reducers....
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