fix: SW-693 Fixed hydration error

This commit is contained in:
Hrishikesh Vaipurkar
2024-10-24 16:50:08 +02:00
parent 76444d6fe9
commit 11e94f42ba
3 changed files with 9 additions and 20 deletions

View File

@@ -22,27 +22,14 @@ export function getSearchHistoryFromLocalStorage() {
}
export const sessionStorageKey = "searchData"
export function getSearchDataFromSessionStorage() {
if (typeof window !== "undefined") {
const storageSearchData = window.sessionStorage.getItem(sessionStorageKey)
if (storageSearchData) {
const parsedStorageSearchData: Location = JSON.parse(storageSearchData)
if (parsedStorageSearchData) {
return parsedStorageSearchData
}
}
}
return undefined
}
export function init(initState: InitState): State {
const searchHistory = getSearchHistoryFromLocalStorage()
const searchData = getSearchDataFromSessionStorage()
return {
defaultLocations: initState.defaultLocations,
locations: [],
search: "",
searchData,
searchData: initState.searchData,
searchHistory,
}
}