clear-react-router 2.2.8 → 2.2.9

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/dist/index.js CHANGED
@@ -688,6 +688,10 @@ var createRouterInstance = (synchronizer) => {
688
688
  });
689
689
  });
690
690
  });
691
+ },
692
+ useRouteItemDataSelector: (callback) => {
693
+ const state = routerState.routeItemDataState;
694
+ return synchronizer(state.subscribe, () => callback(state.getState()));
691
695
  }
692
696
  }
693
697
  };
@@ -867,26 +871,21 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
867
871
  //#endregion
868
872
  //#region hooks/useIsRoutePending.ts
869
873
  var useIsRoutePending = (routePath) => {
870
- const { useRouteItemData } = router.hooks;
871
- const [routeItemData] = useRouteItemData();
872
- return routeItemData.status === "pending" && routeItemData?.location.pathname === routePath;
874
+ const { useRouteItemDataSelector } = router.hooks;
875
+ return useRouteItemDataSelector(({ location: { pathname }, status }) => pathname === routePath && status === "pending");
873
876
  };
874
877
  //#endregion
875
878
  //#region hooks/useNavigate.ts
876
879
  var useNavigate = router.hooks.useNavigate;
877
880
  //#endregion
878
- //#region hooks/useLocation.ts
879
- var useLocation = () => {
880
- const [routeItemData] = router.hooks.useRouteItemData();
881
- return routeItemData.location;
882
- };
883
- //#endregion
884
881
  //#region components/Link.tsx
885
882
  var defaultAs = (props) => /* @__PURE__ */ jsx("a", { ...props });
883
+ var comparator = (to, pathname, exact) => to === "/" ? pathname === "/" : exact ? pathname === to : pathname === to || pathname?.startsWith(`${to}/`);
886
884
  var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact = false, activeClassName = "active-link", pendingClassName = "pending-link", ...rest }) => {
885
+ const { useRouteItemDataSelector } = router.hooks;
887
886
  const isPending = useIsRoutePending(to);
888
- const { pathname } = useLocation();
889
887
  const navigate = useNavigate();
888
+ const isActive = useRouteItemDataSelector(({ location: { pathname } }) => comparator(to, pathname, exact));
890
889
  const timeout = useRef(0);
891
890
  const elementRef = useRef(null);
892
891
  const { defaultPrefetch: configPrefetch, defaultHoverPrefetchDelay: configPrefetchDelay } = routerConfig;
@@ -939,7 +938,6 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
939
938
  useEffect(() => () => {
940
939
  if (timeout.current) clearTimeout(timeout.current);
941
940
  }, []);
942
- const isActive = to === "/" ? pathname === "/" : exact ? pathname === to : pathname === to || pathname?.startsWith(`${to}/`);
943
941
  const normalizedClassName = typeof className === "function" ? className({
944
942
  isActive,
945
943
  isPending
@@ -960,10 +958,10 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
960
958
  await navigate(location);
961
959
  };
962
960
  return as({
963
- ref: elementRef,
964
- style: normalizedStyle,
965
- className: resultClassName,
966
- onClick: clickHandler,
961
+ "ref": elementRef,
962
+ "style": normalizedStyle,
963
+ "className": resultClassName,
964
+ "onClick": clickHandler,
967
965
  href: `${to}${searchString}`,
968
966
  onMouseEnter,
969
967
  onMouseLeave,
@@ -980,6 +978,12 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
980
978
  //#region hooks/useParams.ts
981
979
  var useParams = router.hooks.useParams;
982
980
  //#endregion
981
+ //#region hooks/useLocation.ts
982
+ var useLocation = () => {
983
+ const [routeItemData] = router.hooks.useRouteItemData();
984
+ return routeItemData.location;
985
+ };
986
+ //#endregion
983
987
  //#region hooks/useLoaderState.ts
984
988
  var useLoaderState = router.hooks.useLoaderState;
985
989
  //#endregion
@@ -1025,9 +1029,8 @@ var useAction = router.hooks.useAction;
1025
1029
  //#endregion
1026
1030
  //#region hooks/useIsDataLoading.ts
1027
1031
  var useIsDataLoading = () => {
1028
- const { useRouteItemData } = router.hooks;
1029
- const [routeData] = useRouteItemData();
1030
- return routeData.status === "pending";
1032
+ const { useRouteItemDataSelector } = router.hooks;
1033
+ return useRouteItemDataSelector(({ status }) => status) === "pending";
1031
1034
  };
1032
1035
  //#endregion
1033
1036
  //#region hooks/useRouterContext.ts
package/dist/types.d.ts CHANGED
@@ -145,6 +145,7 @@ export type RouterType = {
145
145
  error: Error | null;
146
146
  }>;
147
147
  useScrollRestoration(restorationBehavior: ScrollRestorationBehavior): () => void;
148
+ useRouteItemDataSelector<T>(callback: (arg: RouteItemData) => T): T;
148
149
  };
149
150
  };
150
151
  export type InvalidateOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "A lightweight routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {