Skip to content

Commit 2912787

Browse files
committed
fix : Changed to work only in browser(storageKey)
- for nextJS (cherry picked from commit e2098fc)
1 parent 2ebe500 commit 2912787

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/localStorage/load.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
export const load = storageKey => JSON.parse(window.localStorage.getItem(storageKey));
1+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
2+
3+
export const load = storageKey => {
4+
if (isBrowser) {
5+
return JSON.parse(window.localStorage.getItem(storageKey));
6+
} else if (storageKey !== undefined) {
7+
console.warn('storageKey support only on browser');
8+
return undefined;
9+
}
10+
};

0 commit comments

Comments
 (0)