Skip to content

Commit 76dc565

Browse files
Add JSDoc to public API (#5555)
* Add JSDoc comments to React Router hooks and components Co-authored-by: tannerlinsley <[email protected]> * Refactor: Rename "Non-obvious props/options" to "Props/Options" Co-authored-by: tannerlinsley <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent da10edf commit 76dc565

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

packages/react-router/src/RouterProvider.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import type {
77
RouterOptions,
88
} from '@tanstack/router-core'
99

10+
/**
11+
* Low-level provider that places the router into React context and optionally
12+
* updates router options from props. Most apps should use `RouterProvider`.
13+
*/
1014
export function RouterContextProvider<
1115
TRouter extends AnyRouter = RegisteredRouter,
1216
TDehydrated extends Record<string, any> = Record<string, any>,
@@ -44,6 +48,15 @@ export function RouterContextProvider<
4448
return provider
4549
}
4650

51+
/**
52+
* Top-level component that renders the active route matches and provides the
53+
* router to the React tree via context.
54+
*
55+
* Accepts the same options as `createRouter` via props to update the router
56+
* instance after creation.
57+
*
58+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction
59+
*/
4760
export function RouterProvider<
4861
TRouter extends AnyRouter = RegisteredRouter,
4962
TDehydrated extends Record<string, any> = Record<string, any>,

packages/react-router/src/link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export function createLink<const TComp>(
539539
* Handles path, search, hash and state updates with optional route preloading
540540
* and active-state styling.
541541
*
542-
* Non-obvious props include:
542+
* Props:
543543
* - `preload`: Controls route preloading (eg. 'intent', 'render', 'viewport', true/false)
544544
* - `preloadDelay`: Delay in ms before preloading on hover
545545
* - `activeProps`/`inactiveProps`: Additional props merged when link is active/inactive

packages/react-router/src/useParams.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ export type UseParamsRoute<out TFrom> = <
6161
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
6262
) => UseParamsResult<TRouter, TFrom, true, TSelected>
6363

64+
/**
65+
* Access the current route's path parameters with type-safety.
66+
*
67+
* Options:
68+
* - `from`/`strict`: Specify the matched route and whether to enforce strict typing
69+
* - `select`: Project the params object to a derived value for memoized renders
70+
* - `structuralSharing`: Enable structural sharing for stable references
71+
* - `shouldThrow`: Throw if the route is not found in strict contexts
72+
*
73+
* @returns The params object (or selected value) for the matched route.
74+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook
75+
*/
6476
export function useParams<
6577
TRouter extends AnyRouter = RegisteredRouter,
6678
const TFrom extends string | undefined = undefined,

packages/react-router/src/useRouter.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import warning from 'tiny-warning'
33
import { getRouterContext } from './routerContext'
44
import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
55

6+
/**
7+
* Access the current TanStack Router instance from React context.
8+
* Must be used within a `RouterProvider`.
9+
*
10+
* Options:
11+
* - `warn`: Log a warning if no router context is found (default: true).
12+
*
13+
* @returns The registered router instance.
14+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
15+
*/
616
export function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
717
warn?: boolean
818
}): TRouter {

packages/react-router/src/useRouterState.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ export type UseRouterStateResult<
2828
TSelected,
2929
> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected
3030

31+
/**
32+
* Subscribe to the router's state store with optional selection and
33+
* structural sharing for render optimization.
34+
*
35+
* Options:
36+
* - `select`: Project the full router state to a derived slice
37+
* - `structuralSharing`: Replace-equal semantics for stable references
38+
* - `router`: Read state from a specific router instance instead of context
39+
*
40+
* @returns The selected router state (or the full state by default).
41+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
42+
*/
3143
export function useRouterState<
3244
TRouter extends AnyRouter = RegisteredRouter,
3345
TSelected = unknown,

packages/react-router/src/useSearch.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ export type UseSearchRoute<out TFrom> = <
6161
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
6262
) => UseSearchResult<TRouter, TFrom, true, TSelected>
6363

64+
/**
65+
* Read and select the current route's search parameters with type-safety.
66+
*
67+
* Options:
68+
* - `from`/`strict`: Control which route's search is read and how strictly it's typed
69+
* - `select`: Map the search object to a derived value for render optimization
70+
* - `structuralSharing`: Enable structural sharing for stable references
71+
* - `shouldThrow`: Throw when the route is not found (strict contexts)
72+
*
73+
* @returns The search object (or selected value) for the matched route.
74+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
75+
*/
6476
export function useSearch<
6577
TRouter extends AnyRouter = RegisteredRouter,
6678
const TFrom extends string | undefined = undefined,

0 commit comments

Comments
 (0)