import { useSearchParams } from "react-router-dom" type QueryParams = { [key in T]: string | undefined } export function useQueryParams( keys: T[], prefix?: string ): QueryParams { const [params] = useSearchParams() // Use a type assertion to initialize the result const result = {} as QueryParams keys.forEach((key) => { const prefixedKey = prefix ? `${prefix}_${key}` : key const value = params.get(prefixedKey) || undefined result[key] = value }) return result }