[questions][fix] searchParam loading from localStorage (#439)

This commit is contained in:
Jeff Sieu
2022-10-26 21:16:10 +08:00
committed by GitHub
parent 87354c6dea
commit 4b835db8a2

View File

@ -42,8 +42,12 @@ export const useSearchParam = <Value = string>(
// 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<string>;
setParams(
loadedFilters
.map(stringToParam)
.filter((value) => value !== null) as Array<Value>,
);
}
}
setIsInitialized(true);