1
- import { useMatch } from './useMatch'
2
1
import type {
3
2
AnyRouter ,
4
3
RegisteredRouter ,
5
4
ResolveUseLoaderDeps ,
6
5
StrictOrFrom ,
7
6
UseLoaderDepsResult ,
8
7
} from '@tanstack/router-core'
8
+ import type { Accessor } from 'solid-js'
9
+ import { useMatch } from './useMatch'
9
10
10
11
export interface UseLoaderDepsBaseOptions <
11
12
TRouter extends AnyRouter ,
@@ -27,20 +28,31 @@ export type UseLoaderDepsRoute<out TId> = <
27
28
TSelected = unknown ,
28
29
> (
29
30
opts ?: UseLoaderDepsBaseOptions < TRouter , TId , TSelected > ,
30
- ) => UseLoaderDepsResult < TRouter , TId , TSelected >
31
+ ) => Accessor < UseLoaderDepsResult < TRouter , TId , TSelected > >
31
32
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
+ */
32
44
export function useLoaderDeps <
33
45
TRouter extends AnyRouter = RegisteredRouter ,
34
46
const TFrom extends string | undefined = undefined ,
35
47
TSelected = unknown ,
36
48
> (
37
49
opts : UseLoaderDepsOptions < TRouter , TFrom , TSelected > ,
38
- ) : UseLoaderDepsResult < TRouter , TFrom , TSelected > {
50
+ ) : Accessor < UseLoaderDepsResult < TRouter , TFrom , TSelected > > {
39
51
const { select, ...rest } = opts
40
52
return useMatch ( {
41
53
...rest ,
42
54
select : ( s ) => {
43
55
return select ? select ( s . loaderDeps ) : s . loaderDeps
44
56
} ,
45
- } ) as UseLoaderDepsResult < TRouter , TFrom , TSelected >
57
+ } ) as Accessor < UseLoaderDepsResult < TRouter , TFrom , TSelected > >
46
58
}
0 commit comments