@tanstack/react-router 1.3.6 → 1.4.1
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/RouterProvider.js +6 -4
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils.js +6 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +12 -7
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/RouterProvider.d.ts +5 -2
- package/build/types/utils.d.ts +2 -1
- package/build/umd/index.development.js +12 -6
- 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/RouterProvider.tsx +12 -5
- package/src/utils.ts +6 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "1.
|
|
47
|
+
"@tanstack/history": "1.4.1"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -235,12 +235,16 @@ export function getRouteMatch<TRouteTree extends AnyRoute>(
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
export function useRouterState<
|
|
238
|
-
|
|
238
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
239
|
+
TSelected = RouterState<TRouteTree>,
|
|
239
240
|
>(opts?: {
|
|
241
|
+
router?: Router<TRouteTree>
|
|
240
242
|
select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected
|
|
241
243
|
}): TSelected {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
+
const contextRouter = useRouter<TRouteTree>({
|
|
245
|
+
warn: opts?.router === undefined,
|
|
246
|
+
})
|
|
247
|
+
return useStore((opts?.router || contextRouter).__store, opts?.select as any)
|
|
244
248
|
}
|
|
245
249
|
|
|
246
250
|
export type RouterProps<
|
|
@@ -253,12 +257,15 @@ export type RouterProps<
|
|
|
253
257
|
|
|
254
258
|
export function useRouter<
|
|
255
259
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
256
|
-
>(): Router<TRouteTree> {
|
|
260
|
+
>(opts?: { warn?: boolean }): Router<TRouteTree> {
|
|
257
261
|
const resolvedContext =
|
|
258
262
|
typeof document !== 'undefined'
|
|
259
263
|
? window.__TSR_ROUTER_CONTEXT__ || routerContext
|
|
260
264
|
: routerContext
|
|
261
265
|
const value = React.useContext(resolvedContext)
|
|
262
|
-
warning(
|
|
266
|
+
warning(
|
|
267
|
+
opts?.warn && value,
|
|
268
|
+
'useRouter must be used inside a <RouterProvider> component!',
|
|
269
|
+
)
|
|
263
270
|
return value as any
|
|
264
271
|
}
|
package/src/utils.ts
CHANGED
|
@@ -141,7 +141,7 @@ export function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
|
-
* This function returns `
|
|
144
|
+
* This function returns `prev` if `_next` is deeply equal.
|
|
145
145
|
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
146
146
|
* This can be used for structural sharing between immutable JSON values for example.
|
|
147
147
|
* Do not use this with signals
|
|
@@ -153,7 +153,7 @@ export function replaceEqualDeep<T>(prev: any, _next: T): T {
|
|
|
153
153
|
|
|
154
154
|
const next = _next as any
|
|
155
155
|
|
|
156
|
-
const array =
|
|
156
|
+
const array = isPlainArray(prev) && isPlainArray(next)
|
|
157
157
|
|
|
158
158
|
if (array || (isPlainObject(prev) && isPlainObject(next))) {
|
|
159
159
|
const prevSize = array ? prev.length : Object.keys(prev).length
|
|
@@ -208,6 +208,10 @@ function hasObjectPrototype(o: any) {
|
|
|
208
208
|
return Object.prototype.toString.call(o) === '[object Object]'
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
export function isPlainArray(value: unknown) {
|
|
212
|
+
return Array.isArray(value) && value.length === Object.keys(value).length
|
|
213
|
+
}
|
|
214
|
+
|
|
211
215
|
export function deepEqual(a: any, b: any, partial: boolean = false): boolean {
|
|
212
216
|
if (a === b) {
|
|
213
217
|
return true
|