fix: JSON parsing fix

This commit is contained in:
Hrishikesh Vaipurkar
2024-11-07 16:24:35 +01:00
parent c456fca19b
commit 256f4dfce3

View File

@@ -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 (