clear-react-router 2.0.3 → 2.0.5
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/README.md +15 -1
- package/dist/hooks/useIsDataLoading.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -4
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -639,6 +639,15 @@ This also works for nested dynamic routes:
|
|
|
639
639
|
await invalidate('/post/[id]/comment/[id]');
|
|
640
640
|
```
|
|
641
641
|
|
|
642
|
+
#### Force revalidation
|
|
643
|
+
By default only paths that already exist in the cache are revalidated.
|
|
644
|
+
Pass `{ force: true }` to also revalidate the exact path(s) you passed, even if they were never cached:
|
|
645
|
+
|
|
646
|
+
```tsx
|
|
647
|
+
await invalidate('/about', { force: true });
|
|
648
|
+
await invalidate(['/about', '/post/10'], { force: true });
|
|
649
|
+
```
|
|
650
|
+
|
|
642
651
|
#### Including child routes
|
|
643
652
|
|
|
644
653
|
To revalidate routes together with their cached child routes, pass the `withChildren` option:
|
|
@@ -691,7 +700,8 @@ Each object represents a revalidated route, where `path` is the route pathname,
|
|
|
691
700
|
|
|
692
701
|
#### Notes
|
|
693
702
|
|
|
694
|
-
* **
|
|
703
|
+
* Without `force` option, **only routes that already have cached data** are revalidated.
|
|
704
|
+
* With `force: true`, the exact pathnames you pass are always revalidated (and stored in the cache).
|
|
695
705
|
* Cached data is cleared before the new loader starts.
|
|
696
706
|
* When used as an event handler, wrap the call in an arrow function:
|
|
697
707
|
|
|
@@ -729,6 +739,10 @@ useEffect(() => {
|
|
|
729
739
|
}, [state, process, reset]);
|
|
730
740
|
```
|
|
731
741
|
|
|
742
|
+
### `useIsDataLoading()`
|
|
743
|
+
|
|
744
|
+
Returns a boolean indicating whether any route loader is currently fetching data. Useful for global loading indicators (progress bar, spinner in the layout, etc.).
|
|
745
|
+
|
|
732
746
|
### `useRouterContext()`
|
|
733
747
|
|
|
734
748
|
Returns the router context object and a function to update it. Useful for accessing or modifying global state (like user authentication, theme, etc.) from anywhere in your app.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useIsDataLoading: () => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { useLoaderState } from './hooks/useLoaderState';
|
|
|
8
8
|
export { useInvalidate } from './hooks/useInvalidate';
|
|
9
9
|
export { useBlocker } from './hooks/useBlocker';
|
|
10
10
|
export { useAction } from './hooks/useAction';
|
|
11
|
+
export { useIsDataLoading } from './hooks/useIsDataLoading';
|
|
11
12
|
export { useRouterContext } from './hooks/useRouterContext';
|
|
12
13
|
export { useSearchParams } from './hooks/useSearchParams';
|
|
13
14
|
export { useFormContext } from './hooks/useFormContext';
|
package/dist/index.js
CHANGED
|
@@ -385,9 +385,10 @@ var createInvalidate = ({ routeItemDataState, loaderStateRef, loaderMap, current
|
|
|
385
385
|
const invalidateItem = async (pathname, options) => {
|
|
386
386
|
const routeItem = findRoute(pathname);
|
|
387
387
|
if (!routeItem) return [];
|
|
388
|
-
const
|
|
389
|
-
for (const [key] of loaderMap) if (comparePaths(routeItem, key))
|
|
390
|
-
|
|
388
|
+
const pathnameSet = /* @__PURE__ */ new Set();
|
|
389
|
+
for (const [key] of loaderMap) if (comparePaths(routeItem, key)) pathnameSet.add(key);
|
|
390
|
+
if (options?.force) pathnameSet.add(pathname);
|
|
391
|
+
const currentResults = await Promise.all([...pathnameSet].map((pathname) => invalidatePath(routeItem, pathname, options)));
|
|
391
392
|
if (!options?.withChildren || !routeItem.children?.length) return currentResults;
|
|
392
393
|
const childResults = await Promise.all(routeItem.children.map((child) => invalidateItem(`${pathname}${child.path}`, options)));
|
|
393
394
|
return [...currentResults, ...childResults.flat()];
|
|
@@ -984,6 +985,13 @@ var useBlocker = (blockerFn) => {
|
|
|
984
985
|
//#region hooks/useAction.ts
|
|
985
986
|
var useAction = router.hooks.useAction;
|
|
986
987
|
//#endregion
|
|
988
|
+
//#region hooks/useIsDataLoading.ts
|
|
989
|
+
var useIsDataLoading = () => {
|
|
990
|
+
const { usePendingState } = router.hooks;
|
|
991
|
+
const [pendingState] = usePendingState();
|
|
992
|
+
return Boolean(pendingState);
|
|
993
|
+
};
|
|
994
|
+
//#endregion
|
|
987
995
|
//#region hooks/useRouterContext.ts
|
|
988
996
|
var useRouterContext = () => {
|
|
989
997
|
const [context, setContext] = router.hooks.useContextState();
|
|
@@ -1061,4 +1069,4 @@ var lazy = (importFn) => ({
|
|
|
1061
1069
|
importFn
|
|
1062
1070
|
});
|
|
1063
1071
|
//#endregion
|
|
1064
|
-
export { Form, Link, Router, createRouter, lazy, useAction, useBlocker, useFormContext, useInvalidate, useLoaderState, useLocation, useNavigate, useParams, useRouterContext, useSearchParams };
|
|
1072
|
+
export { Form, Link, Router, createRouter, lazy, useAction, useBlocker, useFormContext, useInvalidate, useIsDataLoading, useLoaderState, useLocation, useNavigate, useParams, useRouterContext, useSearchParams };
|
package/dist/types.d.ts
CHANGED
|
@@ -157,6 +157,7 @@ export type RouterType = {
|
|
|
157
157
|
export type InvalidateOptions = {
|
|
158
158
|
withChildren?: boolean;
|
|
159
159
|
withBeforeLoad?: boolean;
|
|
160
|
+
force?: boolean;
|
|
160
161
|
};
|
|
161
162
|
export type RevalidateCache = (args: RevalidateCacheArgs) => LoadingPromise;
|
|
162
163
|
export type Options = Partial<{
|