@tanstack/react-router 1.16.6 → 1.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/router.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as React from 'react'
1
2
  import {
2
3
  HistoryLocation,
3
4
  HistoryState,
@@ -133,8 +134,8 @@ export interface RouterOptions<
133
134
  hydrate?: (dehydrated: TDehydrated) => void
134
135
  routeMasks?: RouteMask<TRouteTree>[]
135
136
  unmaskOnReload?: boolean
136
- Wrap?: (props: { children: any }) => JSX.Element
137
- InnerWrap?: (props: { children: any }) => JSX.Element
137
+ Wrap?: (props: { children: any }) => React.ReactNode
138
+ InnerWrap?: (props: { children: any }) => React.ReactNode
138
139
  /**
139
140
  * @deprecated
140
141
  * Use `notFoundComponent` instead.
@@ -5,12 +5,26 @@ import { LinkOptions, NavigateOptions } from './link'
5
5
  import { AnyRoute } from './route'
6
6
  import { RoutePaths } from './routeInfo'
7
7
  import { RegisteredRouter } from './router'
8
- import { StringLiteral } from './utils'
9
8
 
10
- export function useNavigate<
9
+ export type UseNavigateResult<TDefaultFrom extends string> = <
11
10
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
12
- TDefaultFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,
13
- >(_defaultOpts?: { from?: StringLiteral<TDefaultFrom> }) {
11
+ TFrom extends RoutePaths<TRouteTree> | string = TDefaultFrom,
12
+ TTo extends string = '',
13
+ TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,
14
+ TMaskTo extends string = '',
15
+ >({
16
+ from,
17
+ ...rest
18
+ }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>
19
+
20
+ export function useNavigate<
21
+ TDefaultFrom extends string = string,
22
+ >(_defaultOpts?: {
23
+ from?:
24
+ | TDefaultFrom
25
+ | RoutePaths<RegisteredRouter['routeTree']>
26
+ | (string & {})
27
+ }) {
14
28
  const { navigate } = useRouter()
15
29
 
16
30
  const matchPathname = useMatch({
@@ -18,23 +32,14 @@ export function useNavigate<
18
32
  select: (s) => s.pathname,
19
33
  })
20
34
 
21
- return React.useCallback(
22
- <
23
- TFrom extends RoutePaths<TRouteTree> | string = TDefaultFrom,
24
- TTo extends string = '',
25
- TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,
26
- TMaskTo extends string = '',
27
- >({
28
- from,
29
- ...rest
30
- }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => {
31
- return navigate({
32
- from: rest?.to ? matchPathname : undefined,
33
- ...(rest as any),
34
- })
35
- },
36
- [],
37
- )
35
+ const result: UseNavigateResult<TDefaultFrom> = ({ from, ...rest }) => {
36
+ return navigate({
37
+ from: rest?.to ? matchPathname : undefined,
38
+ ...(rest as any),
39
+ })
40
+ }
41
+
42
+ return React.useCallback(result, [])
38
43
  }
39
44
 
40
45
  // NOTE: I don't know of anyone using this. It's undocumented, so let's wait until someone needs it