We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 62b6366 commit aae8daaCopy full SHA for aae8daa
src/index.ts
@@ -26,7 +26,7 @@ export default function createPersistedState(
26
27
let initialOrPersistedValue = initialValue
28
29
- if (initialPersist) {
+ if (initialPersist && initialPersist[key]) {
30
initialOrPersistedValue = (initialPersist[key] as T) || initialValue
31
}
32
@@ -61,7 +61,7 @@ export default function createPersistedState(
61
const handleStorage = (event: StorageEvent): void => {
62
if (event.key === safeStorageKey) {
63
const newState = JSON.parse(event.newValue as string)
64
- const newValue = newState ? newState[key] : initialValue
+ const newValue = newState && newState[key] ? newState[key] : initialValue
65
66
setState(newValue)
67
0 commit comments