feat(SW-977) check if json is valid
This commit is contained in:
@@ -13,6 +13,7 @@ import { useIntl } from "react-intl"
|
||||
|
||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import isValidJson from "@/utils/isValidJson"
|
||||
|
||||
import Input from "../Input"
|
||||
import { init, localStorageKey, reducer, sessionStorageKey } from "./reducer"
|
||||
@@ -129,12 +130,17 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
|
||||
typeof window !== "undefined"
|
||||
? localStorage.getItem(localStorageKey)
|
||||
: null
|
||||
|
||||
if (searchData || searchHistory) {
|
||||
dispatch({
|
||||
payload: {
|
||||
searchData: searchData ? JSON.parse(searchData) : undefined,
|
||||
searchHistory: searchHistory ? JSON.parse(searchHistory) : null,
|
||||
searchData:
|
||||
isValidJson(searchData) && searchData
|
||||
? JSON.parse(searchData)
|
||||
: undefined,
|
||||
searchHistory:
|
||||
isValidJson(searchHistory) && searchHistory
|
||||
? JSON.parse(searchHistory)
|
||||
: null,
|
||||
},
|
||||
type: ActionType.SET_STORAGE_DATA,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user