Skip to content

React Router bindings

The router glue every Capsomer React part needs, in one place.

Anatomy

import { RouterConfirmModal, routerRenderForm, revalidateUnlessOnly, useRouterRowForm } from "capsomer/react/router";
import { onlyParamsChanged } from "capsomer/behavior/router";

API

RouterConfirmModal

PropTypeRequiredDoes
hiddenRecord<string, string | readonly string[]>A list value is one hidden field per item, under one name (the ticked ids).
titlestringYesNames the action and the object: "Delete example.com?"
childrenReactNodeMore fields for the form, beside hidden: a list a server renders as its own inputs.
errorReactNodeWhat the server found wrong the last time (the typed word did not match, no reason): shown in the alert box beside the buttons, so the page works with no script.
reason{ label?: string; note?: string }Asks for a reason, required, that the audit row carries. Posted as reason.
actionstringWhere the form posts, and the fields it carries with it (the intent, the ids, a return address). Left out, it posts to the page it is on.
method"post" | "get"
leadReactNode
bodystring[]What will change, one line each, from the server's own preview.
action_labelstringThe perform button's label, named for the action: "Delete site".
cancelHrefstringYesWhere Cancel goes: a link, so it works with no script.
cancelLabelstring
typeToConfirmstringFor what cannot be recovered: the short word to type. Checked by the browser (required and pattern) and again by the server.
mediabooleanThe icon tile beside the title. Default: shown.
onCancel() => voidCancel for a dialog opened from the page's state rather than its address. Without it, Cancel goes to cancelHref and keeps the scroll position, since the page behind the dialog is where the reader still is.

Functions

FunctionSignatureDoes
useRouterRowForm(): RowFormA row's own fetcher, as a part's useRowForm: <NeedsList useRowForm={useRouterRowForm} />. Each row calls it once, so each row has its own fetcher.
onlyParamsChanged(current: URL, next: URL, display: readonly string[], defaults?: Readonly<Record<string, string>>): booleanTrue when the only change between two addresses is in the named display parameters (a view, a grouping, a size): the same path, every other parameter the same, and at least one named one different. A route's shouldRevalidate then skips the loader, because nothing it reads changed. A missing parameter reads as its default, so ?view=grid and the bare address are the same state when grid is the default. Identical addresses are false: a revalidation after an action has the same address on both sides, and skipping it would hide the write. From dustinedwards.info's media library (app/lib/media/view.mjs, onlyDisplayChanged).