From 291278750502f76a06772c9569321b61a9c6c579 Mon Sep 17 00:00:00 2001 From: Woo Dohyeong Date: Sun, 20 Feb 2022 21:47:03 +0900 Subject: [PATCH] fix : Changed to work only in browser(storageKey) - for nextJS (cherry picked from commit e2098fc2ecaec74ea02c817bc6eb42fa9da05ed1) --- src/localStorage/load.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/localStorage/load.js b/src/localStorage/load.js index 2d55e6843..17d82ff44 100644 --- a/src/localStorage/load.js +++ b/src/localStorage/load.js @@ -1 +1,10 @@ -export const load = storageKey => JSON.parse(window.localStorage.getItem(storageKey)); +const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; + +export const load = storageKey => { + if (isBrowser) { + return JSON.parse(window.localStorage.getItem(storageKey)); + } else if (storageKey !== undefined) { + console.warn('storageKey support only on browser'); + return undefined; + } +};