Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0422078

Browse files
authored
fix(useStorage): fix undefined defaults (#3597)
1 parent bbd2fad commit 0422078

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/core/useStorage/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ describe('useStorage', () => {
113113
expect(storedValue).toBeFalsy()
114114
})
115115

116+
it('undefined value', () => {
117+
storage.removeItem(KEY)
118+
119+
const store = useStorage(KEY, undefined, storage)
120+
const storedValue = storage.getItem(KEY)
121+
122+
expect(store.value).toBe(undefined)
123+
expect(storage.getItem(KEY)).toBe(undefined)
124+
expect(storedValue).toBeFalsy()
125+
})
126+
116127
it('remove value', async () => {
117128
storage.setItem(KEY, 'random')
118129

packages/core/useStorage/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function useStorage<T extends(string | number | boolean | object | null)>
231231
: storage!.getItem(key)
232232

233233
if (rawValue == null) {
234-
if (writeDefaults && rawInit !== null)
234+
if (writeDefaults && rawInit != null)
235235
storage!.setItem(key, serializer.write(rawInit))
236236
return rawInit
237237
}

0 commit comments

Comments
 (0)