grafana/public/app/core/navigation/hooks.ts
Ashley Harrison d2a70bc42d
Chore: more any/type assertion improvements (#57450)
* more friday any/type assertion improvements

* Apply suggestions from code review

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>

* Update public/app/angular/promiseToDigest.test.ts

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2022-10-25 11:04:35 +02:00

19 lines
618 B
TypeScript

import { useLocation } from 'react-router-dom';
import { locationService } from '@grafana/runtime';
export type UseUrlParamsResult = [URLSearchParams, (params: Record<string, unknown>, replace?: boolean) => void];
/** @internal experimental */
export function useUrlParams(): UseUrlParamsResult {
const location = useLocation();
const params = new URLSearchParams(location.search);
const updateUrlParams = (params: Record<string, unknown>, replace?: boolean) => {
// Should find a way to use history directly here
locationService.partial(params, replace);
};
return [params, updateUrlParams];
}