From 4b835db8a21b2de4dd48c86078627364399fbcb3 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Wed, 26 Oct 2022 21:16:10 +0800 Subject: [PATCH] [questions][fix] searchParam loading from localStorage (#439) --- apps/portal/src/utils/questions/useSearchParam.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/portal/src/utils/questions/useSearchParam.ts b/apps/portal/src/utils/questions/useSearchParam.ts index 25208e6e..b8ae89d8 100644 --- a/apps/portal/src/utils/questions/useSearchParam.ts +++ b/apps/portal/src/utils/questions/useSearchParam.ts @@ -42,8 +42,12 @@ export const useSearchParam = ( // Try to load from local storage const localStorageValue = localStorage.getItem(name); if (localStorageValue !== null) { - const loadedFilters = JSON.parse(localStorageValue); - setParams(loadedFilters); + const loadedFilters = JSON.parse(localStorageValue) as Array; + setParams( + loadedFilters + .map(stringToParam) + .filter((value) => value !== null) as Array, + ); } } setIsInitialized(true);