react-router 6.27.0 → 7.0.0-pre.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/CHANGELOG.md +309 -11
- package/README.md +1 -14
- package/dist/dom-export.d.ts +3 -0
- package/dist/dom-export.mjs +205 -0
- package/dist/dom-export.mjs.map +1 -0
- package/dist/index.d.ts +74 -29
- package/dist/index.mjs +11543 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/components.d.ts +250 -35
- package/dist/lib/context.d.ts +18 -5
- package/dist/lib/dom/dom.d.ts +123 -0
- package/dist/lib/dom/global.d.ts +40 -0
- package/dist/lib/dom/lib.d.ts +940 -0
- package/dist/lib/dom/server.d.ts +41 -0
- package/dist/lib/dom/ssr/components.d.ts +123 -0
- package/dist/lib/dom/ssr/data.d.ts +7 -0
- package/dist/lib/dom/ssr/entry.d.ts +47 -0
- package/dist/lib/dom/ssr/errorBoundaries.d.ts +36 -0
- package/dist/lib/dom/ssr/errors.d.ts +2 -0
- package/dist/lib/dom/ssr/fallback.d.ts +2 -0
- package/dist/lib/dom/ssr/fog-of-war.d.ts +28 -0
- package/dist/lib/dom/ssr/invariant.d.ts +2 -0
- package/dist/lib/dom/ssr/links.d.ts +25 -0
- package/dist/lib/dom/ssr/markup.d.ts +5 -0
- package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
- package/dist/lib/dom/ssr/routes-test-stub.d.ts +59 -0
- package/dist/lib/dom/ssr/routes.d.ts +32 -0
- package/dist/lib/dom/ssr/server.d.ts +16 -0
- package/dist/lib/dom/ssr/single-fetch.d.ts +37 -0
- package/dist/lib/dom-export/dom-router-provider.d.ts +5 -0
- package/dist/lib/dom-export/hydrated-router.d.ts +5 -0
- package/dist/lib/dom-export.d.ts +3 -0
- package/dist/lib/hooks.d.ts +286 -57
- package/dist/lib/router/history.d.ts +253 -0
- package/dist/lib/router/links.d.ts +104 -0
- package/dist/lib/router/router.d.ts +540 -0
- package/dist/lib/router/utils.d.ts +505 -0
- package/dist/lib/server-runtime/build.d.ts +38 -0
- package/dist/lib/server-runtime/cookies.d.ts +62 -0
- package/dist/lib/server-runtime/crypto.d.ts +2 -0
- package/dist/lib/server-runtime/data.d.ts +15 -0
- package/dist/lib/server-runtime/dev.d.ts +8 -0
- package/dist/lib/server-runtime/entry.d.ts +3 -0
- package/dist/lib/server-runtime/errors.d.ts +51 -0
- package/dist/lib/server-runtime/headers.d.ts +3 -0
- package/dist/lib/server-runtime/invariant.d.ts +2 -0
- package/dist/lib/server-runtime/jsonify.d.ts +33 -0
- package/dist/lib/server-runtime/markup.d.ts +1 -0
- package/dist/lib/server-runtime/mode.d.ts +9 -0
- package/dist/lib/server-runtime/responses.d.ts +37 -0
- package/dist/lib/server-runtime/routeMatching.d.ts +8 -0
- package/dist/lib/server-runtime/routeModules.d.ts +212 -0
- package/dist/lib/server-runtime/routes.d.ts +31 -0
- package/dist/lib/server-runtime/server.d.ts +5 -0
- package/dist/lib/server-runtime/serverHandoff.d.ts +11 -0
- package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +19 -0
- package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +17 -0
- package/dist/lib/server-runtime/sessions.d.ts +140 -0
- package/dist/lib/server-runtime/single-fetch.d.ts +30 -0
- package/dist/lib/server-runtime/typecheck.d.ts +4 -0
- package/dist/lib/server-runtime/warnings.d.ts +1 -0
- package/dist/lib/types.d.ts +76 -0
- package/dist/lib/types.mjs +10 -0
- package/dist/main-dom-export.js +19 -0
- package/dist/main.js +1 -1
- package/dist/react-router-dom.development.js +199 -0
- package/dist/react-router-dom.development.js.map +1 -0
- package/dist/react-router-dom.production.min.js +12 -0
- package/dist/react-router-dom.production.min.js.map +1 -0
- package/dist/react-router.development.js +12281 -1141
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router-dom.development.js +241 -0
- package/dist/umd/react-router-dom.development.js.map +1 -0
- package/dist/umd/react-router-dom.production.min.js +12 -0
- package/dist/umd/react-router-dom.production.min.js.map +1 -0
- package/dist/umd/react-router.development.js +12467 -1238
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +35 -6
- package/dist/index.js +0 -1467
- package/dist/index.js.map +0 -1
package/dist/lib/hooks.d.ts
CHANGED
|
@@ -1,38 +1,62 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import type { Blocker, BlockerFunction, Location, ParamParseKey, Params, Path, PathMatch, PathPattern, RelativeRoutingType, Router as RemixRouter, RevalidationState, To, UIMatch } from "@remix-run/router";
|
|
3
|
-
import { Action as NavigationType } from "@remix-run/router";
|
|
4
2
|
import type { NavigateOptions, RouteContextObject, RouteMatch, RouteObject } from "./context";
|
|
3
|
+
import type { Location, Path, To } from "./router/history";
|
|
4
|
+
import { Action as NavigationType } from "./router/history";
|
|
5
|
+
import type { Blocker, BlockerFunction, RelativeRoutingType, Router as DataRouter, RevalidationState } from "./router/router";
|
|
6
|
+
import type { ParamParseKey, Params, PathMatch, PathPattern, UIMatch } from "./router/utils";
|
|
5
7
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Resolves a URL against the current location.
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { useHref } from "react-router"
|
|
12
|
+
|
|
13
|
+
function SomeComponent() {
|
|
14
|
+
let href = useHref("some/where");
|
|
15
|
+
// "/resolved/some/where"
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@category Hooks
|
|
10
20
|
*/
|
|
11
21
|
export declare function useHref(to: To, { relative }?: {
|
|
12
22
|
relative?: RelativeRoutingType;
|
|
13
23
|
}): string;
|
|
14
24
|
/**
|
|
15
|
-
* Returns true if this component is a descendant of a
|
|
25
|
+
* Returns true if this component is a descendant of a Router, useful to ensure
|
|
26
|
+
* a component is used within a Router.
|
|
16
27
|
*
|
|
17
|
-
* @
|
|
28
|
+
* @category Hooks
|
|
18
29
|
*/
|
|
19
30
|
export declare function useInRouterContext(): boolean;
|
|
20
31
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
Returns the current {@link Location}. This can be useful if you'd like to perform some side effect whenever it changes.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import * as React from 'react'
|
|
36
|
+
import { useLocation } from 'react-router'
|
|
37
|
+
|
|
38
|
+
function SomeComponent() {
|
|
39
|
+
let location = useLocation()
|
|
40
|
+
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
// Google Analytics
|
|
43
|
+
ga('send', 'pageview')
|
|
44
|
+
}, [location]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
// ...
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
@category Hooks
|
|
29
53
|
*/
|
|
30
54
|
export declare function useLocation(): Location;
|
|
31
55
|
/**
|
|
32
56
|
* Returns the current navigation action which describes how the router came to
|
|
33
57
|
* the current location, either by a pop, push, or replace on the history stack.
|
|
34
58
|
*
|
|
35
|
-
* @
|
|
59
|
+
* @category Hooks
|
|
36
60
|
*/
|
|
37
61
|
export declare function useNavigationType(): NavigationType;
|
|
38
62
|
/**
|
|
@@ -40,63 +64,130 @@ export declare function useNavigationType(): NavigationType;
|
|
|
40
64
|
* This is useful for components that need to know "active" state, e.g.
|
|
41
65
|
* `<NavLink>`.
|
|
42
66
|
*
|
|
43
|
-
* @
|
|
67
|
+
* @category Hooks
|
|
44
68
|
*/
|
|
45
69
|
export declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
|
|
46
70
|
/**
|
|
47
71
|
* The interface for the navigate() function returned from useNavigate().
|
|
48
72
|
*/
|
|
49
73
|
export interface NavigateFunction {
|
|
50
|
-
(to: To, options?: NavigateOptions): void
|
|
51
|
-
(delta: number): void
|
|
74
|
+
(to: To, options?: NavigateOptions): void | Promise<void>;
|
|
75
|
+
(delta: number): void | Promise<void>;
|
|
52
76
|
}
|
|
53
77
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
Returns a function that lets you navigate programmatically in the browser in response to user interactions or effects.
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { useNavigate } from "react-router";
|
|
82
|
+
|
|
83
|
+
function SomeComponent() {
|
|
84
|
+
let navigate = useNavigate();
|
|
85
|
+
return (
|
|
86
|
+
<button
|
|
87
|
+
onClick={() => {
|
|
88
|
+
navigate(-1);
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
It's often better to use {@link redirect} in {@link ActionFunction | actions} and {@link LoaderFunction | loaders} than this hook.
|
|
96
|
+
|
|
97
|
+
@category Hooks
|
|
58
98
|
*/
|
|
59
99
|
export declare function useNavigate(): NavigateFunction;
|
|
60
100
|
/**
|
|
61
|
-
* Returns the
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
101
|
+
* Returns the parent route {@link OutletProps.context | `<Outlet context>`}.
|
|
102
|
+
*
|
|
103
|
+
* @category Hooks
|
|
64
104
|
*/
|
|
65
105
|
export declare function useOutletContext<Context = unknown>(): Context;
|
|
66
106
|
/**
|
|
67
107
|
* Returns the element for the child route at this level of the route
|
|
68
108
|
* hierarchy. Used internally by `<Outlet>` to render child routes.
|
|
69
109
|
*
|
|
70
|
-
* @
|
|
110
|
+
* @category Hooks
|
|
71
111
|
*/
|
|
72
112
|
export declare function useOutlet(context?: unknown): React.ReactElement | null;
|
|
73
113
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
114
|
+
Returns an object of key/value pairs of the dynamic params from the current URL that were matched by the routes. Child routes inherit all params from their parent routes.
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import { useParams } from "react-router"
|
|
118
|
+
|
|
119
|
+
function SomeComponent() {
|
|
120
|
+
let params = useParams()
|
|
121
|
+
params.postId
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Assuming a route pattern like `/posts/:postId` is matched by `/posts/123` then `params.postId` will be `"123"`.
|
|
126
|
+
|
|
127
|
+
@category Hooks
|
|
78
128
|
*/
|
|
79
129
|
export declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
|
|
80
130
|
ParamsOrKey
|
|
81
131
|
] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>>;
|
|
82
132
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
133
|
+
Resolves the pathname of the given `to` value against the current location. Similar to {@link useHref}, but returns a {@link Path} instead of a string.
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { useResolvedPath } from "react-router"
|
|
137
|
+
|
|
138
|
+
function SomeComponent() {
|
|
139
|
+
// if the user is at /dashboard/profile
|
|
140
|
+
let path = useResolvedPath("../accounts")
|
|
141
|
+
path.pathname // "/dashboard/accounts"
|
|
142
|
+
path.search // ""
|
|
143
|
+
path.hash // ""
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
@category Hooks
|
|
86
148
|
*/
|
|
87
149
|
export declare function useResolvedPath(to: To, { relative }?: {
|
|
88
150
|
relative?: RelativeRoutingType;
|
|
89
151
|
}): Path;
|
|
90
152
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
153
|
+
Hook version of {@link Routes | `<Routes>`} that uses objects instead of components. These objects have the same properties as the component props.
|
|
154
|
+
|
|
155
|
+
The return value of `useRoutes` is either a valid React element you can use to render the route tree, or `null` if nothing matched.
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import * as React from "react";
|
|
159
|
+
import { useRoutes } from "react-router";
|
|
160
|
+
|
|
161
|
+
function App() {
|
|
162
|
+
let element = useRoutes([
|
|
163
|
+
{
|
|
164
|
+
path: "/",
|
|
165
|
+
element: <Dashboard />,
|
|
166
|
+
children: [
|
|
167
|
+
{
|
|
168
|
+
path: "messages",
|
|
169
|
+
element: <DashboardMessages />,
|
|
170
|
+
},
|
|
171
|
+
{ path: "tasks", element: <DashboardTasks /> },
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
{ path: "team", element: <AboutPage /> },
|
|
175
|
+
]);
|
|
176
|
+
|
|
177
|
+
return element;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
@category Hooks
|
|
97
182
|
*/
|
|
98
183
|
export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
|
|
99
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Internal implementation with accept optional param for RouterProvider usage
|
|
186
|
+
*
|
|
187
|
+
* @private
|
|
188
|
+
* @category Hooks
|
|
189
|
+
*/
|
|
190
|
+
export declare function useRoutesImpl(routes: RouteObject[], locationArg?: Partial<Location> | string, dataRouterState?: DataRouter["state"], future?: DataRouter["future"]): React.ReactElement | null;
|
|
100
191
|
type RenderErrorBoundaryProps = React.PropsWithChildren<{
|
|
101
192
|
location: Location;
|
|
102
193
|
revalidation: RevalidationState;
|
|
@@ -122,53 +213,189 @@ export declare class RenderErrorBoundary extends React.Component<RenderErrorBoun
|
|
|
122
213
|
componentDidCatch(error: any, errorInfo: any): void;
|
|
123
214
|
render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
|
|
124
215
|
}
|
|
125
|
-
export declare function _renderMatches(matches: RouteMatch[] | null, parentMatches?: RouteMatch[], dataRouterState?:
|
|
216
|
+
export declare function _renderMatches(matches: RouteMatch[] | null, parentMatches?: RouteMatch[], dataRouterState?: DataRouter["state"] | null, future?: DataRouter["future"] | null): React.ReactElement | null;
|
|
126
217
|
/**
|
|
127
218
|
* Returns the ID for the nearest contextual route
|
|
128
219
|
*/
|
|
129
220
|
export declare function useRouteId(): string;
|
|
130
221
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
222
|
+
Returns the current navigation, defaulting to an "idle" navigation when no navigation is in progress. You can use this to render pending UI (like a global spinner) or read FormData from a form navigation.
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
import { useNavigation } from "react-router"
|
|
226
|
+
|
|
227
|
+
function SomeComponent() {
|
|
228
|
+
let navigation = useNavigation();
|
|
229
|
+
navigation.state
|
|
230
|
+
navigation.formData
|
|
231
|
+
// etc.
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
@category Hooks
|
|
133
236
|
*/
|
|
134
|
-
export declare function useNavigation(): import("
|
|
237
|
+
export declare function useNavigation(): import("./router/router").Navigation;
|
|
135
238
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
239
|
+
Revalidate the data on the page for reasons outside of normal data mutations like window focus or polling on an interval.
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
import { useRevalidator } from "react-router";
|
|
243
|
+
|
|
244
|
+
function WindowFocusRevalidator() {
|
|
245
|
+
const revalidator = useRevalidator();
|
|
246
|
+
|
|
247
|
+
useFakeWindowFocus(() => {
|
|
248
|
+
revalidator.revalidate();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<div hidden={revalidator.state === "idle"}>
|
|
253
|
+
Revalidating...
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Note that page data is already revalidated automatically after actions. If you find yourself using this for normal CRUD operations on your data in response to user interactions, you're probably not taking advantage of the other APIs like {@link useFetcher}, {@link Form}, {@link useSubmit} that do this automatically.
|
|
260
|
+
|
|
261
|
+
@category Hooks
|
|
138
262
|
*/
|
|
139
263
|
export declare function useRevalidator(): {
|
|
140
|
-
revalidate
|
|
264
|
+
revalidate(): Promise<void>;
|
|
141
265
|
state: RevalidationState;
|
|
142
266
|
};
|
|
143
267
|
/**
|
|
144
268
|
* Returns the active route matches, useful for accessing loaderData for
|
|
145
269
|
* parent/child routes or the route "handle" property
|
|
270
|
+
*
|
|
271
|
+
* @category Hooks
|
|
146
272
|
*/
|
|
147
273
|
export declare function useMatches(): UIMatch[];
|
|
148
274
|
/**
|
|
149
|
-
|
|
275
|
+
Returns the data from the closest route {@link LoaderFunction | loader} or {@link ClientLoaderFunction | client loader}.
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
import { useLoaderData } from "react-router"
|
|
279
|
+
|
|
280
|
+
export async function loader() {
|
|
281
|
+
return await fakeDb.invoices.findAll();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export default function Invoices() {
|
|
285
|
+
let invoices = useLoaderData<typeof loader>();
|
|
286
|
+
// ...
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
@category Hooks
|
|
150
291
|
*/
|
|
151
292
|
export declare function useLoaderData(): unknown;
|
|
152
293
|
/**
|
|
153
|
-
|
|
294
|
+
Returns the loader data for a given route by route ID.
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import { useRouteLoaderData } from "react-router";
|
|
298
|
+
|
|
299
|
+
function SomeComponent() {
|
|
300
|
+
const { user } = useRouteLoaderData("root");
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Route IDs are created automatically. They are simply the path of the route file relative to the app folder without the extension.
|
|
305
|
+
|
|
306
|
+
| Route Filename | Route ID |
|
|
307
|
+
| -------------------------- | -------------------- |
|
|
308
|
+
| `app/root.tsx` | `"root"` |
|
|
309
|
+
| `app/routes/teams.tsx` | `"routes/teams"` |
|
|
310
|
+
| `app/whatever/teams.$id.tsx` | `"whatever/teams.$id"` |
|
|
311
|
+
|
|
312
|
+
If you created an ID manually, you can use that instead:
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
route("/", "containers/app.tsx", { id: "app" }})
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
@category Hooks
|
|
154
319
|
*/
|
|
155
320
|
export declare function useRouteLoaderData(routeId: string): unknown;
|
|
156
321
|
/**
|
|
157
|
-
|
|
322
|
+
Returns the action data from the most recent POST navigation form submission or `undefined` if there hasn't been one.
|
|
323
|
+
|
|
324
|
+
```tsx
|
|
325
|
+
import { Form, useActionData } from "react-router"
|
|
326
|
+
|
|
327
|
+
export async function action({ request }) {
|
|
328
|
+
const body = await request.formData()
|
|
329
|
+
const name = body.get("visitorsName")
|
|
330
|
+
return { message: `Hello, ${name}` }
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export default function Invoices() {
|
|
334
|
+
const data = useActionData()
|
|
335
|
+
return (
|
|
336
|
+
<Form method="post">
|
|
337
|
+
<input type="text" name="visitorsName" />
|
|
338
|
+
{data ? data.message : "Waiting..."}
|
|
339
|
+
</Form>
|
|
340
|
+
)
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
@category Hooks
|
|
158
345
|
*/
|
|
159
346
|
export declare function useActionData(): unknown;
|
|
160
347
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
348
|
+
Accesses the error thrown during an {@link ActionFunction | action}, {@link LoaderFunction | loader}, or component render to be used in a route module Error Boundary.
|
|
349
|
+
|
|
350
|
+
```tsx
|
|
351
|
+
export function ErrorBoundary() {
|
|
352
|
+
const error = useRouteError();
|
|
353
|
+
return <div>{error.message}</div>;
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
@category Hooks
|
|
164
358
|
*/
|
|
165
359
|
export declare function useRouteError(): unknown;
|
|
166
360
|
/**
|
|
167
|
-
|
|
361
|
+
Returns the resolved promise value from the closest {@link Await | `<Await>`}.
|
|
362
|
+
|
|
363
|
+
```tsx
|
|
364
|
+
function SomeDescendant() {
|
|
365
|
+
const value = useAsyncValue();
|
|
366
|
+
// ...
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// somewhere in your app
|
|
370
|
+
<Await resolve={somePromise}>
|
|
371
|
+
<SomeDescendant />
|
|
372
|
+
</Await>
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
@category Hooks
|
|
168
376
|
*/
|
|
169
377
|
export declare function useAsyncValue(): unknown;
|
|
170
378
|
/**
|
|
171
|
-
|
|
379
|
+
Returns the rejection value from the closest {@link Await | `<Await>`}.
|
|
380
|
+
|
|
381
|
+
```tsx
|
|
382
|
+
import { Await, useAsyncError } from "react-router"
|
|
383
|
+
|
|
384
|
+
function ErrorElement() {
|
|
385
|
+
const error = useAsyncError();
|
|
386
|
+
return (
|
|
387
|
+
<p>Uh Oh, something went wrong! {error.message}</p>
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// somewhere in your app
|
|
392
|
+
<Await
|
|
393
|
+
resolve={promiseThatRejects}
|
|
394
|
+
errorElement={<ErrorElement />}
|
|
395
|
+
/>
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
@category Hooks
|
|
172
399
|
*/
|
|
173
400
|
export declare function useAsyncError(): unknown;
|
|
174
401
|
/**
|
|
@@ -176,6 +403,8 @@ export declare function useAsyncError(): unknown;
|
|
|
176
403
|
* user a confirmation dialog to confirm the navigation. Mostly used to avoid
|
|
177
404
|
* using half-filled form data. This does not handle hard-reloads or
|
|
178
405
|
* cross-origin navigations.
|
|
406
|
+
*
|
|
407
|
+
* @category Hooks
|
|
179
408
|
*/
|
|
180
409
|
export declare function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker;
|
|
181
410
|
export {};
|