const getSearchParams = (): Partial => { // server side rendering if (typeof window === "undefined") { return {}; } const params = new URLSearchParams(window.location.search); return new Proxy(params, { get(target, prop, receiver) { return target.get(prop as string) || undefined; }, }) as T; }; export const useSearchParams = (): Partial => { const [searchParams, setSearchParams] = useState(getSearchParams()); useEffect(() => { setSearchParams(getSearchParams()); }, [typeof window === "undefined" ? "once" : window.location.search]); return searchParams; };