Skip to content

Commit

Permalink
[@mantine/hooks]: Fix storage access error in create-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
yongwee committed Oct 21, 2023
1 parent 05e26d7 commit e5be8f2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/mantine-hooks/src/use-local-storage/create-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,19 @@ export function createStorage<T>(type: StorageType, hookName: string) {
}: StorageProperties<T>) {
const readStorageValue = useCallback(
(skipStorage?: boolean): T => {
if (
typeof window === 'undefined' ||
!(type in window) ||
window[type] === null ||
skipStorage
) {
let storageBlockedOrSkipped;

try {
storageBlockedOrSkipped =
typeof window === 'undefined' ||
!(type in window) ||
window[type] === null ||
!!skipStorage;
} catch (_e) {
storageBlockedOrSkipped = true;
}

if (storageBlockedOrSkipped) {
return defaultValue as T;
}

Expand Down

0 comments on commit e5be8f2

Please sign in to comment.