@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.
@@ -25,11 +25,14 @@ export type InjectedHtmlEntry = string | (() => Promise<string> | string);
25
25
  export declare let routerContext: React.Context<Router<any, Record<string, any>>>;
26
26
  export declare function RouterProvider<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>): React.JSX.Element;
27
27
  export declare function getRouteMatch<TRouteTree extends AnyRoute>(state: RouterState<TRouteTree>, id: string): undefined | RouteMatch<TRouteTree>;
28
- export declare function useRouterState<TSelected = RouterState<RegisteredRouter['routeTree']>>(opts?: {
28
+ export declare function useRouterState<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TSelected = RouterState<TRouteTree>>(opts?: {
29
+ router?: Router<TRouteTree>;
29
30
  select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected;
30
31
  }): TSelected;
31
32
  export type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
32
33
  router: Router<TRouteTree>;
33
34
  context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
34
35
  };
35
- export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): Router<TRouteTree>;
36
+ export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(opts?: {
37
+ warn?: boolean;
38
+ }): Router<TRouteTree>;
@@ -25,13 +25,14 @@ export declare function last<T>(arr: T[]): T | undefined;
25
25
  export declare function functionalUpdate<TResult>(updater: Updater<TResult> | NonNullableUpdater<TResult>, previous: TResult): TResult;
26
26
  export declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
27
27
  /**
28
- * This function returns `a` if `b` is deeply equal.
28
+ * This function returns `prev` if `_next` is deeply equal.
29
29
  * If not, it will replace any deeply equal children of `b` with those of `a`.
30
30
  * This can be used for structural sharing between immutable JSON values for example.
31
31
  * Do not use this with signals
32
32
  */
33
33
  export declare function replaceEqualDeep<T>(prev: any, _next: T): T;
34
34
  export declare function isPlainObject(o: any): boolean;
35
+ export declare function isPlainArray(value: unknown): boolean;
35
36
  export declare function deepEqual(a: any, b: any, partial?: boolean): boolean;
36
37
  export declare function useStableCallback<T extends (...args: any[]) => any>(fn: T): T;
37
38
  export declare function shallow<T>(objA: T, objB: T): boolean;
@@ -797,7 +797,7 @@
797
797
  }
798
798
 
799
799
  /**
800
- * This function returns `a` if `b` is deeply equal.
800
+ * This function returns `prev` if `_next` is deeply equal.
801
801
  * If not, it will replace any deeply equal children of `b` with those of `a`.
802
802
  * This can be used for structural sharing between immutable JSON values for example.
803
803
  * Do not use this with signals
@@ -807,7 +807,7 @@
807
807
  return prev;
808
808
  }
809
809
  const next = _next;
810
- const array = Array.isArray(prev) && Array.isArray(next);
810
+ const array = isPlainArray(prev) && isPlainArray(next);
811
811
  if (array || isPlainObject(prev) && isPlainObject(next)) {
812
812
  const prevSize = array ? prev.length : Object.keys(prev).length;
813
813
  const nextItems = array ? next : Object.keys(next);
@@ -855,6 +855,9 @@
855
855
  function hasObjectPrototype(o) {
856
856
  return Object.prototype.toString.call(o) === '[object Object]';
857
857
  }
858
+ function isPlainArray(value) {
859
+ return Array.isArray(value) && value.length === Object.keys(value).length;
860
+ }
858
861
  function deepEqual(a, b, partial = false) {
859
862
  if (a === b) {
860
863
  return true;
@@ -1218,13 +1221,15 @@
1218
1221
  return [...state.cachedMatches, ...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
1219
1222
  }
1220
1223
  function useRouterState(opts) {
1221
- const router = useRouter();
1222
- return useStore(router.__store, opts?.select);
1224
+ const contextRouter = useRouter({
1225
+ warn: opts?.router === undefined
1226
+ });
1227
+ return useStore((opts?.router || contextRouter).__store, opts?.select);
1223
1228
  }
1224
- function useRouter() {
1229
+ function useRouter(opts) {
1225
1230
  const resolvedContext = typeof document !== 'undefined' ? window.__TSR_ROUTER_CONTEXT__ || exports.routerContext : exports.routerContext;
1226
1231
  const value = React__namespace.useContext(resolvedContext);
1227
- warning(value, 'useRouter must be used inside a <RouterProvider> component!');
1232
+ warning(opts?.warn && value, 'useRouter must be used inside a <RouterProvider> component!');
1228
1233
  return value;
1229
1234
  }
1230
1235
 
@@ -3439,6 +3444,7 @@
3439
3444
  exports.interpolatePath = interpolatePath;
3440
3445
  exports.invariant = invariant;
3441
3446
  exports.isDehydratedDeferred = isDehydratedDeferred;
3447
+ exports.isPlainArray = isPlainArray;
3442
3448
  exports.isPlainObject = isPlainObject;
3443
3449
  exports.isRedirect = isRedirect;
3444
3450
  exports.isServer = isServer;