feat(dashboard): DataTable component (#6297)
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { useSearchParams } from "react-router-dom"
|
||||
|
||||
type QueryParams<T extends string> = {
|
||||
[key in T]: string | undefined
|
||||
}
|
||||
|
||||
export function useQueryParams<T extends string>(
|
||||
keys: T[]
|
||||
): Record<T, string | undefined> {
|
||||
keys: T[],
|
||||
prefix?: string
|
||||
): QueryParams<T> {
|
||||
const [params] = useSearchParams()
|
||||
|
||||
// Use a type assertion to initialize the result
|
||||
const result = {} as Record<T, string | undefined>
|
||||
const result = {} as QueryParams<T>
|
||||
|
||||
keys.forEach((key) => {
|
||||
result[key] = params.get(key) || undefined
|
||||
const prefixedKey = prefix ? `${prefix}_${key}` : key
|
||||
const value = params.get(prefixedKey) || undefined
|
||||
|
||||
result[key] = value
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user