@tanstack/react-router 0.0.1-beta.22 → 0.0.1-beta.23

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.22",
4
+ "version": "0.0.1-beta.23",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router/",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@babel/runtime": "^7.16.7",
44
- "@tanstack/router-core": "0.0.1-beta.21",
44
+ "@tanstack/router-core": "0.0.1-beta.23",
45
45
  "use-sync-external-store": "^1.2.0"
46
46
  },
47
47
  "devDependencies": {
package/src/index.tsx CHANGED
@@ -7,8 +7,10 @@ import {
7
7
  CheckId,
8
8
  rootRouteId,
9
9
  Route,
10
+ RouterContext,
10
11
  RouterState,
11
12
  ToIdOption,
13
+ UnionToIntersection,
12
14
  } from '@tanstack/router-core'
13
15
  import {
14
16
  warning,
@@ -146,6 +148,10 @@ declare module '@tanstack/router-core' {
146
148
  Component: RouteComponent
147
149
  }
148
150
 
151
+ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
152
+ useContext?: () => RouterContext
153
+ }
154
+
149
155
  interface Router<
150
156
  TRouteConfig extends AnyRouteConfig = RouteConfig,
151
157
  TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>,
@@ -488,9 +494,15 @@ export function RouterProvider<
488
494
  >({ children, router, ...rest }: RouterProps<TRouteConfig, TAllRouteInfo>) {
489
495
  router.update(rest)
490
496
 
497
+ const defaultRouterContext = React.useRef({})
498
+
499
+ const userContext =
500
+ router.options.useContext?.() ?? defaultRouterContext.current
501
+
502
+ router.context = userContext
503
+
491
504
  useRouterSubscription(router)
492
505
  React.useEffect(() => {
493
- console.log('hello')
494
506
  return router.mount()
495
507
  }, [router])
496
508
 
@@ -557,6 +569,12 @@ export function useRoute<
557
569
  return router.useRoute(routeId as any) as any
558
570
  }
559
571
 
572
+ export function useSearch<
573
+ TId extends keyof RegisteredAllRouteInfo['routeInfoById'] = keyof RegisteredAllRouteInfo['routeInfoById'],
574
+ >(_routeId?: TId): RegisteredAllRouteInfo['fullSearchSchema'] {
575
+ return useRouter().state.location.search
576
+ }
577
+
560
578
  export function linkProps<TTo extends string = '.'>(
561
579
  props: MakeLinkPropsOptions<RegisteredAllRouteInfo, '/', TTo>,
562
580
  ): React.AnchorHTMLAttributes<HTMLAnchorElement> {
@@ -606,8 +624,6 @@ export function Outlet() {
606
624
  Outlet,
607
625
  )
608
626
  }
609
-
610
- console.log(match.matchId, 'suspend')
611
627
  throw match.__.loadPromise
612
628
  })() as JSX.Element
613
629
  }