@tanstack/react-router 0.0.1-beta.176 → 0.0.1-beta.178

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.176",
4
+ "version": "0.0.1-beta.178",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "tiny-warning": "^1.0.3",
45
45
  "@tanstack/react-store": "^0.0.1",
46
46
  "@gisatcz/cross-package-react-context": "^0.2.0",
47
- "@tanstack/router-core": "0.0.1-beta.176"
47
+ "@tanstack/router-core": "0.0.1-beta.178"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/react.tsx CHANGED
@@ -190,38 +190,24 @@ export type RouteProps<
190
190
  TRouteContext extends AnyContext = AnyContext,
191
191
  TAllContext extends AnyContext = AnyContext,
192
192
  > = {
193
- useLoader: <TStrict extends boolean = true, TSelected = TLoader>(opts?: {
194
- strict?: TStrict
193
+ useLoader: <TSelected = TLoader>(opts?: {
195
194
  select?: (search: TLoader) => TSelected
196
- }) => TStrict extends true
197
- ? UseLoaderResult<TSelected>
198
- : UseLoaderResult<TSelected> | undefined
199
- useMatch: <TStrict extends boolean = true, TSelected = TAllContext>(opts?: {
200
- strict?: TStrict
195
+ }) => UseLoaderResult<TSelected>
196
+ useMatch: <TSelected = TAllContext>(opts?: {
201
197
  select?: (search: TAllContext) => TSelected
202
- }) => TStrict extends true ? TSelected : TSelected | undefined
203
- useContext: <TStrict extends boolean = true, TSelected = TAllContext>(opts?: {
204
- strict?: TStrict
198
+ }) => TSelected
199
+ useContext: <TSelected = TAllContext>(opts?: {
205
200
  select?: (search: TAllContext) => TSelected
206
- }) => TStrict extends true ? TSelected : TSelected | undefined
207
- useRouteContext: <
208
- TStrict extends boolean = true,
209
- TSelected = TRouteContext,
210
- >(opts?: {
211
- strict?: TStrict
201
+ }) => TSelected
202
+ useRouteContext: <TSelected = TRouteContext>(opts?: {
212
203
  select?: (search: TRouteContext) => TSelected
213
- }) => TStrict extends true ? TSelected : TSelected | undefined
214
- useSearch: <
215
- TStrict extends boolean = true,
216
- TSelected = TFullSearchSchema,
217
- >(opts?: {
218
- strict?: TStrict
204
+ }) => TSelected
205
+ useSearch: <TSelected = TFullSearchSchema>(opts?: {
219
206
  select?: (search: TFullSearchSchema) => TSelected
220
- }) => TStrict extends true ? TSelected : TSelected | undefined
221
- useParams: <TStrict extends boolean = true, TSelected = TAllParams>(opts?: {
222
- strict?: TStrict
207
+ }) => TSelected
208
+ useParams: <TSelected = TAllParams>(opts?: {
223
209
  select?: (search: TAllParams) => TSelected
224
- }) => TStrict extends true ? TSelected : TSelected | undefined
210
+ }) => TSelected
225
211
  }
226
212
 
227
213
  export type ErrorRouteProps<
@@ -271,14 +257,15 @@ Route.__onInit = (route) => {
271
257
  return useMatch({
272
258
  ...opts,
273
259
  from: route.id,
274
- select: (d: any) => opts?.select?.(d.context) ?? d.context,
260
+ select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
275
261
  } as any)
276
262
  },
277
263
  useRouteContext: (opts: any = {}) => {
278
264
  return useMatch({
279
265
  ...opts,
280
266
  from: route.id,
281
- select: (d: any) => opts?.select?.(d.routeContext) ?? d.routeContext,
267
+ select: (d: any) =>
268
+ opts?.select ? opts.select(d.routeContext) : d.routeContext,
282
269
  } as any)
283
270
  },
284
271
  useSearch: (opts = {}) => {
@@ -660,7 +647,7 @@ export function useMatches<T = RouteMatch[]>(opts?: {
660
647
  const matches = state.matches.slice(
661
648
  state.matches.findIndex((d) => d.id === matchIds[0]),
662
649
  )
663
- return (opts?.select?.(matches) ?? matches) as T
650
+ return opts?.select ? opts.select(matches) : (matches as T)
664
651
  },
665
652
  })
666
653
  }
@@ -716,7 +703,7 @@ export function useMatch<
716
703
  )
717
704
  }
718
705
 
719
- const match = useRouterState({
706
+ const matchSelection = useRouterState({
720
707
  select: (state) => {
721
708
  const matches = state.matches
722
709
  const match = opts?.from
@@ -732,11 +719,11 @@ export function useMatch<
732
719
  }`,
733
720
  )
734
721
 
735
- return (opts?.select?.(match as any) ?? match) as TSelected
722
+ return opts?.select ? opts.select(match as any) : match
736
723
  },
737
724
  })
738
725
 
739
- return match as any
726
+ return matchSelection as any
740
727
  }
741
728
 
742
729
  export type RouteFromIdOrRoute<T> = T extends ParseRoute<
@@ -762,8 +749,9 @@ export function useLoader<
762
749
  return useMatch({
763
750
  ...(opts as any),
764
751
  select: (match: RouteMatch) =>
765
- (opts?.select?.(match.loaderData as TLoader) ??
766
- match.loaderData) as TSelected,
752
+ opts?.select
753
+ ? opts?.select(match.loaderData as TLoader)
754
+ : match.loaderData,
767
755
  })
768
756
  }
769
757
 
@@ -783,7 +771,7 @@ export function useRouterContext<
783
771
  return useMatch({
784
772
  ...(opts as any),
785
773
  select: (match: RouteMatch) =>
786
- (opts?.select?.(match.context as TContext) ?? match.context) as TSelected,
774
+ opts?.select ? opts.select(match.context as TContext) : match.context,
787
775
  })
788
776
  }
789
777
 
@@ -803,8 +791,9 @@ export function useRouteContext<
803
791
  return useMatch({
804
792
  ...(opts as any),
805
793
  select: (match: RouteMatch) =>
806
- (opts?.select?.(match.routeContext as TRouteContext) ??
807
- match.routeContext) as TSelected,
794
+ opts?.select
795
+ ? opts.select(match.routeContext as TRouteContext)
796
+ : match.routeContext,
808
797
  })
809
798
  }
810
799
 
@@ -824,8 +813,7 @@ export function useSearch<
824
813
  return useMatch({
825
814
  ...(opts as any),
826
815
  select: (match: RouteMatch) => {
827
- return (opts?.select?.(match.search as TSearch) ??
828
- match.search) as TSelected
816
+ return opts?.select ? opts.select(match.search as TSearch) : match.search
829
817
  },
830
818
  })
831
819
  }
@@ -843,7 +831,7 @@ export function useParams<
843
831
  return useRouterState({
844
832
  select: (state: any) => {
845
833
  const params = (last(state.matches) as any)?.params
846
- return (opts?.select?.(params) ?? params) as TSelected
834
+ return opts?.select ? opts.select(params) : params
847
835
  },
848
836
  })
849
837
  }