Skip to content

Commit aeb4871

Browse files
📝 Add docstrings to fix/solid-router-use-loader-deps-accessor
Docstrings generation was requested by @edmolima. * #5348 (comment) The following files were modified: * `packages/solid-router/src/useLoaderDeps.tsx`
1 parent ac35dd2 commit aeb4871

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/solid-router/src/useLoaderDeps.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { useMatch } from './useMatch'
21
import type {
32
AnyRouter,
43
RegisteredRouter,
54
ResolveUseLoaderDeps,
65
StrictOrFrom,
76
UseLoaderDepsResult,
87
} from '@tanstack/router-core'
8+
import type { Accessor } from 'solid-js'
9+
import { useMatch } from './useMatch'
910

1011
export interface UseLoaderDepsBaseOptions<
1112
TRouter extends AnyRouter,
@@ -27,20 +28,31 @@ export type UseLoaderDepsRoute<out TId> = <
2728
TSelected = unknown,
2829
>(
2930
opts?: UseLoaderDepsBaseOptions<TRouter, TId, TSelected>,
30-
) => UseLoaderDepsResult<TRouter, TId, TSelected>
31+
) => Accessor<UseLoaderDepsResult<TRouter, TId, TSelected>>
3132

33+
/**
34+
* Selects and returns the matched route's loader dependencies as a Solid `Accessor`.
35+
*
36+
* When a `select` function is provided in `opts`, the accessor yields the result of applying
37+
* that function to the matched route's `loaderDeps`. Otherwise the accessor yields the
38+
* route's raw `loaderDeps`.
39+
*
40+
* @param opts - Options that specify which route to match and an optional `select` mapper
41+
* to transform the matched route's `loaderDeps`.
42+
* @returns An `Accessor` that yields the selected loader dependencies for the matched route.
43+
*/
3244
export function useLoaderDeps<
3345
TRouter extends AnyRouter = RegisteredRouter,
3446
const TFrom extends string | undefined = undefined,
3547
TSelected = unknown,
3648
>(
3749
opts: UseLoaderDepsOptions<TRouter, TFrom, TSelected>,
38-
): UseLoaderDepsResult<TRouter, TFrom, TSelected> {
50+
): Accessor<UseLoaderDepsResult<TRouter, TFrom, TSelected>> {
3951
const { select, ...rest } = opts
4052
return useMatch({
4153
...rest,
4254
select: (s) => {
4355
return select ? select(s.loaderDeps) : s.loaderDeps
4456
},
45-
}) as UseLoaderDepsResult<TRouter, TFrom, TSelected>
57+
}) as Accessor<UseLoaderDepsResult<TRouter, TFrom, TSelected>>
4658
}

0 commit comments

Comments
 (0)