Default value ignores/overwrites previous localStorage state
See original GitHub issueHey 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:
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:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome thanks @astoilkov !!
Wow. That’s actually a very bad bug. I fixed it and published a new release.
Thanks, @tnrich!
Closing this issue.