@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/build/cjs/react.js +11 -11
- package/build/cjs/react.js.map +1 -1
- package/build/esm/index.js +11 -11
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +98 -98
- package/build/types/react.d.ts +12 -18
- package/build/umd/index.development.js +38 -54
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/react.tsx +28 -40
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.
|
|
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.
|
|
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: <
|
|
194
|
-
strict?: TStrict
|
|
193
|
+
useLoader: <TSelected = TLoader>(opts?: {
|
|
195
194
|
select?: (search: TLoader) => TSelected
|
|
196
|
-
}) =>
|
|
197
|
-
|
|
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
|
-
}) =>
|
|
203
|
-
useContext: <
|
|
204
|
-
strict?: TStrict
|
|
198
|
+
}) => TSelected
|
|
199
|
+
useContext: <TSelected = TAllContext>(opts?: {
|
|
205
200
|
select?: (search: TAllContext) => TSelected
|
|
206
|
-
}) =>
|
|
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
|
-
}) =>
|
|
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
|
-
}) =>
|
|
221
|
-
useParams: <
|
|
222
|
-
strict?: TStrict
|
|
207
|
+
}) => TSelected
|
|
208
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
223
209
|
select?: (search: TAllParams) => TSelected
|
|
224
|
-
}) =>
|
|
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
|
|
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) =>
|
|
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
|
|
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
|
|
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
|
|
722
|
+
return opts?.select ? opts.select(match as any) : match
|
|
736
723
|
},
|
|
737
724
|
})
|
|
738
725
|
|
|
739
|
-
return
|
|
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
|
-
|
|
766
|
-
match.loaderData
|
|
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
|
-
|
|
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
|
-
|
|
807
|
-
match.routeContext
|
|
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
|
|
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
|
|
834
|
+
return opts?.select ? opts.select(params) : params
|
|
847
835
|
},
|
|
848
836
|
})
|
|
849
837
|
}
|