Skip to content

Commit

Permalink
fix(clear): dispatch event with old value
Browse files Browse the repository at this point in the history
  • Loading branch information
Akurganow committed Jun 2, 2020
1 parent c420a15 commit 38e05ef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export default function createPersistedState(
): [<T>(key: string, initialValue: T) => UsePersistedState<T>, () => void] {
const safeStorageKey = `persisted_state_hook:${storageKey}`
const clear = (): void => {
const oldValue = storage.getItem(safeStorageKey)
storage.removeItem(safeStorageKey)
window.dispatchEvent(new StorageEvent('storage', { key: safeStorageKey }))
window.dispatchEvent(new StorageEvent('storage', { key: safeStorageKey, oldValue }))
}

const usePersistedState = <T>(key: string, initialValue: T): UsePersistedState<T> => {
Expand Down

0 comments on commit 38e05ef

Please sign in to comment.