Files
med-notes/.pnpm-store/v10/files/90/477108a50a8160b2efc35abe60868a86941ac1da8cb6203231947e4ffb48311a94689a841969ea639cb08856bc965684e009757cae1fcce72d6a66a16abf28
2025-05-09 05:30:08 +02:00

42 lines
1.2 KiB
Plaintext

import { useRouterState } from './useRouterState'
import type {
StructuralSharingOption,
ValidateSelected,
} from './structuralSharing'
import type {
AnyRouter,
RegisteredRouter,
RouterState,
} from '@tanstack/router-core'
export interface UseLocationBaseOptions<
TRouter extends AnyRouter,
TSelected,
TStructuralSharing extends boolean = boolean,
> {
select?: (
state: RouterState<TRouter['routeTree']>['location'],
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
}
export type UseLocationResult<
TRouter extends AnyRouter,
TSelected,
> = unknown extends TSelected
? RouterState<TRouter['routeTree']>['location']
: TSelected
export function useLocation<
TRouter extends AnyRouter = RegisteredRouter,
TSelected = unknown,
TStructuralSharing extends boolean = boolean,
>(
opts?: UseLocationBaseOptions<TRouter, TSelected, TStructuralSharing> &
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
): UseLocationResult<TRouter, TSelected> {
return useRouterState({
select: (state: any) =>
opts?.select ? opts.select(state.location) : state.location,
} as any) as UseLocationResult<TRouter, TSelected>
}