Skip to content

Commit

Permalink
🐛 removeItem() reference isn't stable
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Aug 8, 2024
1 parent e06e7e9 commit 045e92e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/useStorageState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ function useStorage<T>(
[key, storage, stringify],
)

const removeItem = useCallback(() => {
goodTry(() => storage.removeItem(key))
triggerCallbacks(key)
}, [key, storage])

// - syncs change across tabs, windows, iframes
// - the `storage` event is called only in all tabs, windows, iframe's except the one that
// triggered the change
Expand All @@ -167,12 +172,9 @@ function useStorage<T>(
() => [
value,
setState,
(): void => {
goodTry(() => storage.removeItem(key))
triggerCallbacks(key)
},
removeItem,
],
[value, setState, storage, key],
[value, setState, removeItem],
)
}

Expand Down

0 comments on commit 045e92e

Please sign in to comment.