grafana/public/app/features/alerting/unified/hooks/useURLSearchParams.ts

19 lines
627 B
TypeScript
Raw Normal View History

import { useCallback, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { locationService } from '@grafana/runtime';
export function useURLSearchParams(): [
URLSearchParams,
(searchValues: Record<string, string | string[] | undefined>, replace?: boolean) => void
] {
const { search } = useLocation();
const queryParams = useMemo(() => new URLSearchParams(search), [search]);
const update = useCallback((searchValues: Record<string, string | string[] | undefined>, replace?: boolean) => {
locationService.partial(searchValues, replace);
}, []);
return [queryParams, update];
}