diff --git a/packages/solid-router/src/useLoaderDeps.tsx b/packages/solid-router/src/useLoaderDeps.tsx index 91e5acb308..4563ff09d5 100644 --- a/packages/solid-router/src/useLoaderDeps.tsx +++ b/packages/solid-router/src/useLoaderDeps.tsx @@ -1,4 +1,3 @@ -import { useMatch } from './useMatch' import type { AnyRouter, RegisteredRouter, @@ -6,6 +5,8 @@ import type { StrictOrFrom, UseLoaderDepsResult, } from '@tanstack/router-core' +import type { Accessor } from 'solid-js' +import { useMatch } from './useMatch' export interface UseLoaderDepsBaseOptions< TRouter extends AnyRouter, @@ -27,20 +28,31 @@ export type UseLoaderDepsRoute = < TSelected = unknown, >( opts?: UseLoaderDepsBaseOptions, -) => UseLoaderDepsResult +) => Accessor> +/** + * Selects and returns the matched route's loader dependencies as a Solid `Accessor`. + * + * When a `select` function is provided in `opts`, the accessor yields the result of applying + * that function to the matched route's `loaderDeps`. Otherwise the accessor yields the + * route's raw `loaderDeps`. + * + * @param opts - Options that specify which route to match and an optional `select` mapper + * to transform the matched route's `loaderDeps`. + * @returns An `Accessor` that yields the selected loader dependencies for the matched route. + */ export function useLoaderDeps< TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TSelected = unknown, >( opts: UseLoaderDepsOptions, -): UseLoaderDepsResult { +): Accessor> { const { select, ...rest } = opts return useMatch({ ...rest, select: (s) => { return select ? select(s.loaderDeps) : s.loaderDeps }, - }) as UseLoaderDepsResult + }) as Accessor> }