2022-01-28 02:40:05 -06:00
|
|
|
import { useCallback, useMemo } from 'react';
|
2022-01-13 03:48:13 -06:00
|
|
|
import { useLocation } from 'react-router-dom';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-01-28 02:40:05 -06:00
|
|
|
import { locationService } from '@grafana/runtime';
|
2022-01-13 03:48:13 -06:00
|
|
|
|
2022-01-28 02:40:05 -06:00
|
|
|
export function useURLSearchParams(): [
|
|
|
|
URLSearchParams,
|
|
|
|
(searchValues: Record<string, string | string[] | undefined>, replace?: boolean) => void
|
|
|
|
] {
|
2022-01-13 03:48:13 -06:00
|
|
|
const { search } = useLocation();
|
|
|
|
const queryParams = useMemo(() => new URLSearchParams(search), [search]);
|
2022-01-28 02:40:05 -06:00
|
|
|
|
|
|
|
const update = useCallback((searchValues: Record<string, string | string[] | undefined>, replace?: boolean) => {
|
|
|
|
locationService.partial(searchValues, replace);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return [queryParams, update];
|
2022-01-13 03:48:13 -06:00
|
|
|
}
|