hooks.ts 610 B

123456789101112131415161718
  1. import { useLocation } from 'react-router-dom';
  2. import { locationService } from '@grafana/runtime';
  3. export type UseUrlParamsResult = [URLSearchParams, (params: Record<string, any>, replace?: boolean) => void];
  4. /** @internal experimental */
  5. export function useUrlParams(): UseUrlParamsResult {
  6. const location = useLocation();
  7. const params = new URLSearchParams(location.search);
  8. const updateUrlParams = (params: Record<string, any>, replace?: boolean) => {
  9. // Should find a way to use history directly here
  10. locationService.partial(params, replace);
  11. };
  12. return [params, updateUrlParams];
  13. }