From 256f4dfce3f8bfe1988cde61f735c22931bd888b Mon Sep 17 00:00:00 2001 From: Hrishikesh Vaipurkar Date: Thu, 7 Nov 2024 16:24:35 +0100 Subject: [PATCH] fix: JSON parsing fix --- .../FormContent/Search/index.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/components/Forms/BookingWidget/FormContent/Search/index.tsx b/components/Forms/BookingWidget/FormContent/Search/index.tsx index 40ed40ebd..ac820da51 100644 --- a/components/Forms/BookingWidget/FormContent/Search/index.tsx +++ b/components/Forms/BookingWidget/FormContent/Search/index.tsx @@ -117,19 +117,21 @@ export default function Search({ locations }: SearchProps) { useEffect(() => { const searchData = typeof window !== "undefined" - ? JSON.parse(sessionStorage.getItem(sessionStorageKey) || "") + ? sessionStorage.getItem(sessionStorageKey) : undefined const searchHistory = typeof window !== "undefined" - ? JSON.parse(localStorage.getItem(localStorageKey) || "") + ? localStorage.getItem(localStorageKey) : null - dispatch({ - payload: { - searchData, - searchHistory, - }, - type: ActionType.SET_STORAGE_DATA, - }) + if (searchData || searchHistory) { + dispatch({ + payload: { + searchData: searchData ? JSON.parse(searchData) : undefined, + searchHistory: searchHistory ? JSON.parse(searchHistory) : null, + }, + type: ActionType.SET_STORAGE_DATA, + }) + } }, [dispatch]) return (