useParams.tsx 730 B

123456789101112131415161718
  1. import {useMemo} from 'react';
  2. import {customerDomain, usingCustomerDomain} from 'sentry/constants';
  3. import {useRouteContext} from 'sentry/utils/useRouteContext';
  4. export function useParams<P = Record<string, string>>(): P {
  5. const contextParams = useRouteContext().params;
  6. // Memoize params as mutating for customer domains causes other hooks
  7. // that depend on `useParams()` to refresh infinitely.
  8. return useMemo(() => {
  9. if (usingCustomerDomain && customerDomain && contextParams.orgId === undefined) {
  10. // We do not know if the caller of this hook requires orgId, so we populate orgId implicitly.
  11. return {...contextParams, orgId: customerDomain};
  12. }
  13. return contextParams;
  14. }, [contextParams]);
  15. }