Skip to content

errorBoundary()

Wrap a subtree with a fallback that renders when something inside throws. Prefer this over a hand-rolled try/catch in a component setup.

function errorBoundary(
fallback: (error: Error, retry: () => void) => WhisqNode,
child: () => WhisqNode,
): WhisqNode
ParamTypeDescription
fallback(error: Error, retry: () => void) => WhisqNodeRendered when the wrapped subtree throws. retry re-runs child
child() => WhisqNodeThe protected subtree, wrapped in a thunk so retry can re-invoke it
import { errorBoundary, div, p, button } from "@whisq/core";
errorBoundary(
(error, retry) =>
div({ class: "error-boundary" },
p(`Something went wrong: ${error.message}`),
button({ onclick: retry }, "Try again"),
),
() => RiskyComponent({}),
);

See Advanced → Error Boundaries for granular wrapping, error reporting, and how the primitive composes with resource().