Skip to content

Commit

Permalink
fix(empty key): check that key in persisted storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Akurganow committed Sep 9, 2019
1 parent 62b6366 commit aae8daa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function createPersistedState(

let initialOrPersistedValue = initialValue

if (initialPersist) {
if (initialPersist && initialPersist[key]) {
initialOrPersistedValue = (initialPersist[key] as T) || initialValue
}

Expand Down Expand Up @@ -61,7 +61,7 @@ export default function createPersistedState(
const handleStorage = (event: StorageEvent): void => {
if (event.key === safeStorageKey) {
const newState = JSON.parse(event.newValue as string)
const newValue = newState ? newState[key] : initialValue
const newValue = newState && newState[key] ? newState[key] : initialValue

setState(newValue)
}
Expand Down

0 comments on commit aae8daa

Please sign in to comment.