Skip to content

Commit 25d4741

Browse files
committed
chore: generate markdown docs from jsdocs
1 parent 20c3ed9 commit 25d4741

File tree

6 files changed

+161
-10
lines changed

6 files changed

+161
-10
lines changed

docs/api/data-routers/createBrowserRouter.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,55 @@ const router = createBrowserRouter(
329329
);
330330
```
331331

332+
### opts.unstable_instrumentations
333+
334+
Array of instrumentation objects allowing you to instrument the router and
335+
individual routes prior to router initialization (and on any subsequently
336+
added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
337+
mostly useful for observability such as wrapping navigations, fetches,
338+
as well as route loaders/actions/middlewares with logging and/or performance
339+
tracing.
340+
341+
```tsx
342+
let router = createBrowserRouter(routes, {
343+
unstable_instrumentations: [logging]
344+
});
345+
346+
347+
let logging = {
348+
router({ instrument }) {
349+
instrument({
350+
navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
351+
fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
352+
});
353+
},
354+
route({ instrument, id }) {
355+
instrument({
356+
middleware: (impl, info) => logExecution(
357+
`middleware ${info.request.url} (route ${id})`,
358+
impl
359+
),
360+
loader: (impl, info) => logExecution(
361+
`loader ${info.request.url} (route ${id})`,
362+
impl
363+
),
364+
action: (impl, info) => logExecution(
365+
`action ${info.request.url} (route ${id})`,
366+
impl
367+
),
368+
})
369+
}
370+
};
371+
372+
async function logExecution(label: string, impl: () => Promise<void>) {
373+
let start = performance.now();
374+
console.log(`start ${label}`);
375+
await impl();
376+
let duration = Math.round(performance.now() - start);
377+
console.log(`end ${label} (${duration}ms)`);
378+
}
379+
```
380+
332381
### opts.patchRoutesOnNavigation
333382

334383
Lazily define portions of the route tree on navigations.

docs/api/data-routers/createHashRouter.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,55 @@ const router = createBrowserRouter(
142142
);
143143
```
144144

145+
### opts.unstable_instrumentations
146+
147+
Array of instrumentation objects allowing you to instrument the router and
148+
individual routes prior to router initialization (and on any subsequently
149+
added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
150+
mostly useful for observability such as wrapping navigations, fetches,
151+
as well as route loaders/actions/middlewares with logging and/or performance
152+
tracing.
153+
154+
```tsx
155+
let router = createBrowserRouter(routes, {
156+
unstable_instrumentations: [logging]
157+
});
158+
159+
160+
let logging = {
161+
router({ instrument }) {
162+
instrument({
163+
navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
164+
fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
165+
});
166+
},
167+
route({ instrument, id }) {
168+
instrument({
169+
middleware: (impl, info) => logExecution(
170+
`middleware ${info.request.url} (route ${id})`,
171+
impl
172+
),
173+
loader: (impl, info) => logExecution(
174+
`loader ${info.request.url} (route ${id})`,
175+
impl
176+
),
177+
action: (impl, info) => logExecution(
178+
`action ${info.request.url} (route ${id})`,
179+
impl
180+
),
181+
})
182+
}
183+
};
184+
185+
async function logExecution(label: string, impl: () => Promise<void>) {
186+
let start = performance.now();
187+
console.log(`start ${label}`);
188+
await impl();
189+
let duration = Math.round(performance.now() - start);
190+
console.log(`end ${label} (${duration}ms)`);
191+
}
192+
```
193+
145194
### opts.dataStrategy
146195

147196
Override the default data strategy of running loaders in parallel.

docs/api/data-routers/createMemoryRouter.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,55 @@ Initial entries in the in-memory history stack
7575

7676
Index of `initialEntries` the application should initialize to
7777

78+
### opts.unstable_instrumentations
79+
80+
Array of instrumentation objects allowing you to instrument the router and
81+
individual routes prior to router initialization (and on any subsequently
82+
added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
83+
mostly useful for observability such as wrapping navigations, fetches,
84+
as well as route loaders/actions/middlewares with logging and/or performance
85+
tracing.
86+
87+
```tsx
88+
let router = createBrowserRouter(routes, {
89+
unstable_instrumentations: [logging]
90+
});
91+
92+
93+
let logging = {
94+
router({ instrument }) {
95+
instrument({
96+
navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
97+
fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
98+
});
99+
},
100+
route({ instrument, id }) {
101+
instrument({
102+
middleware: (impl, info) => logExecution(
103+
`middleware ${info.request.url} (route ${id})`,
104+
impl
105+
),
106+
loader: (impl, info) => logExecution(
107+
`loader ${info.request.url} (route ${id})`,
108+
impl
109+
),
110+
action: (impl, info) => logExecution(
111+
`action ${info.request.url} (route ${id})`,
112+
impl
113+
),
114+
})
115+
}
116+
};
117+
118+
async function logExecution(label: string, impl: () => Promise<void>) {
119+
let start = performance.now();
120+
console.log(`start ${label}`);
121+
await impl();
122+
let duration = Math.round(performance.now() - start);
123+
console.log(`end ${label} (${duration}ms)`);
124+
}
125+
```
126+
78127
### opts.patchRoutesOnNavigation
79128

80129
Lazily define portions of the route tree on navigations.

docs/api/framework-routers/HydratedRouter.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ function HydratedRouter(props: HydratedRouterProps)
3333

3434
### getContext
3535

36-
Context object to be passed through to [`createBrowserRouter`](../data-routers/createBrowserRouter) and made
37-
available to
36+
Context factory function to be passed through to [`createBrowserRouter`](../data-routers/createBrowserRouter).
37+
This function will be called to create a fresh `context` instance on each
38+
navigation/fetch and made available to
3839
[`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
39-
functions
40+
functions.
4041

4142
### unstable_onError
4243

docs/api/hooks/useNavigate.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ The returned function signature is `navigate(to, options?)`/`navigate(delta)` wh
3232

3333
* `to` can be a string path, a [`To`](https://api.reactrouter.com/v7/types/react_router.To.html) object, or a number (delta)
3434
* `options` contains options for modifying the navigation
35-
* `flushSync`: Wrap the DOM updates in [`ReactDom.flushSync`](https://react.dev/reference/react-dom/flushSync)
36-
* `preventScrollReset`: Do not scroll back to the top of the page after navigation
37-
* `relative`: `"route"` or `"path"` to control relative routing logic
38-
* `replace`: Replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History) stack
39-
* `state`: Optional [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state) to include with the new [`Location`](https://api.reactrouter.com/v7/interfaces/react_router.Location.html)
40-
* `viewTransition`: Enable [`document.startViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for this navigation
35+
* These options work in all modes (Framework, Data, and Declarative):
36+
* `relative`: `"route"` or `"path"` to control relative routing logic
37+
* `replace`: Replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History) stack
38+
* `state`: Optional [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state) to include with the new [`Location`](https://api.reactrouter.com/v7/interfaces/react_router.Location.html)
39+
* These options only work in Framework and Data modes:
40+
* `flushSync`: Wrap the DOM updates in [`ReactDom.flushSync`](https://react.dev/reference/react-dom/flushSync)
41+
* `preventScrollReset`: Do not scroll back to the top of the page after navigation
42+
* `viewTransition`: Enable [`document.startViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for this navigation
4143

4244
```tsx
4345
import { useNavigate } from "react-router";

docs/api/utils/isRouteErrorResponse.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/ro
2424

2525
Check if the given error is an [`ErrorResponse`](https://api.reactrouter.com/v7/types/react_router.ErrorResponse.html) generated from a 4xx/5xx
2626
[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
27-
thrown from an [`action`](../../start/framework/route-module#action)/[`loader`](../../start/framework/route-module#loader)
27+
thrown from an [`action`](../../start/framework/route-module#action) or
28+
[`loader`](../../start/framework/route-module#loader) function.
2829

2930
```tsx
3031
import { isRouteErrorResponse } from "react-router";

0 commit comments

Comments
 (0)