Skip to content

Commit 68f7f91

Browse files
authored
Add jsdocs for static routers (#14014)
1 parent 84425b9 commit 68f7f91

File tree

4 files changed

+86
-33
lines changed

4 files changed

+86
-33
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"packages/react-router/lib/dom/lib.tsx",
2828
"packages/react-router/lib/dom/ssr/components.tsx",
2929
"packages/react-router/lib/dom/ssr/server.tsx",
30-
"packages/react-router/lib/dom-export/hydrated-router.tsx"
30+
"packages/react-router/lib/dom-export/hydrated-router.tsx",
31+
"packages/react-router/lib/dom/server.tsx"
3132
],
3233
"plugins": ["jsdoc"],
3334
"rules": {

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
pnpm run docs:jsdoc --path packages/react-router/lib/dom/ssr/components.tsx --write
5555
pnpm run docs:jsdoc --path packages/react-router/lib/dom/ssr/server.tsx --write
5656
pnpm run docs:jsdoc --path packages/react-router/lib/dom-export/hydrated-router.tsx --write
57+
pnpm run docs:jsdoc --path packages/react-router/lib/dom/server.tsx --write
5758
5859
- name: 💪 Commit
5960
run: |

docs/api/utils/createStaticHandler.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/react-router/lib/dom/server.tsx

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ export interface StaticRouterProps {
4646
* A `<Router>` that may not navigate to any other location. This is useful
4747
* on the server where there is no stateful UI.
4848
*
49+
* @public
4950
* @category Declarative Routers
51+
* @mode declarative
52+
* @param props Props
53+
* @param props.basename The base URL for the static router (default: `/`)
54+
* @param props.children The child elements to render inside the static router
55+
* @param props.location The location to render the static router at (default: `/`)
56+
* @returns A React element that renders the static router
5057
*/
5158
export function StaticRouter({
5259
basename,
@@ -90,7 +97,32 @@ export interface StaticRouterProviderProps {
9097
* A Data Router that may not navigate to any other location. This is useful
9198
* on the server where there is no stateful UI.
9299
*
100+
* @example
101+
* export async function handleRequest(request: Request) {
102+
* let { query, dataRoutes } = createStaticHandler(routes);
103+
* let context = await query(request));
104+
*
105+
* if (context instanceof Response) {
106+
* return context;
107+
* }
108+
*
109+
* let router = createStaticRouter(dataRoutes, context);
110+
* return new Response(
111+
* ReactDOMServer.renderToString(<StaticRouterProvider ... />),
112+
* { headers: { "Content-Type": "text/html" } }
113+
* );
114+
* }
115+
*
116+
* @public
93117
* @category Data Routers
118+
* @mode data
119+
* @param props Props
120+
* @param props.context The {@link StaticHandlerContext} returned from `staticHandler.query()`
121+
* @param props.router The static data router from {@link createStaticRouter}
122+
* @param props.hydrate Whether to hydrate the router on the client (default `true`)
123+
* @param props.nonce The [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
124+
* to use for the hydration `<script>` tag
125+
* @returns A React element that renders the static router provider
94126
*/
95127
export function StaticRouterProvider({
96128
context,
@@ -255,7 +287,32 @@ type CreateStaticHandlerOptions = Omit<
255287
>;
256288

257289
/**
258-
* @category Utils
290+
* Create a static handler to perform server-side data loading
291+
*
292+
* @example
293+
* export async function handleRequest(request: Request) {
294+
* let { query, dataRoutes } = createStaticHandler(routes);
295+
* let context = await query(request));
296+
*
297+
* if (context instanceof Response) {
298+
* return context;
299+
* }
300+
*
301+
* let router = createStaticRouter(dataRoutes, context);
302+
* return new Response(
303+
* ReactDOMServer.renderToString(<StaticRouterProvider ... />),
304+
* { headers: { "Content-Type": "text/html" } }
305+
* );
306+
* }
307+
*
308+
* @public
309+
* @category Data Routers
310+
* @mode data
311+
* @param routes The route objects to create a static handler for
312+
* @param opts Options
313+
* @param opts.basename The base URL for the static handler (default: `/`)
314+
* @param opts.future Future flags for the static handler
315+
* @returns A static handler that can be used to query data for the provided routes
259316
*/
260317
export function createStaticHandler(
261318
routes: RouteObject[],
@@ -268,7 +325,32 @@ export function createStaticHandler(
268325
}
269326

270327
/**
328+
* Create a static data router for server-side rendering
329+
*
330+
* @example
331+
* export async function handleRequest(request: Request) {
332+
* let { query, dataRoutes } = createStaticHandler(routes);
333+
* let context = await query(request));
334+
*
335+
* if (context instanceof Response) {
336+
* return context;
337+
* }
338+
*
339+
* let router = createStaticRouter(dataRoutes, context);
340+
* return new Response(
341+
* ReactDOMServer.renderToString(<StaticRouterProvider ... />),
342+
* { headers: { "Content-Type": "text/html" } }
343+
* );
344+
* }
345+
*
346+
* @public
271347
* @category Data Routers
348+
* @mode data
349+
* @param routes The route objects to create a static data router for
350+
* @param context The static handler context returned from `staticHandler.query()`
351+
* @param opts Options
352+
* @param opts.future Future flags for the static data router
353+
* @returns A static data router that can be used to render the provided routes
272354
*/
273355
export function createStaticRouter(
274356
routes: RouteObject[],

0 commit comments

Comments
 (0)