useUrlOpen

Read-only URL state for open/closed components.

Use useUrlOpen for dialogs, sheets, alert dialogs, and popovers that should reflect URL state without storing open state internally.

The hook is route-agnostic and always serializes open-state values as strings.

Usage

import { useUrlOpen } from "@tilt-legal/cubitt-components/utilities/hooks";

export function Dialog() {
  const { isOpen, open, close } = useUrlOpen({
    paramName: "dialog",
  });

  return (
    <YourDialog
      open={isOpen}
      onOpenChange={(value) => (value ? void open() : void close())}
    />
  );
}

Router registration

When your app registers its TanStack Router, paramName narrows to known search keys from the route tree. Without registration, it falls back to loose string typing but still works at runtime.

API

OptionTypeDescriptionDefault
paramNamestringURL parameter name. Narrows to known search keys when your router is registered.-
paramMatchValuestringOpen only when the URL value matches this string-
onUrlValueChangefunctionCallback when the URL value changes-
paramClearOnDefaultbooleanRemove the parameter when closedtrue
paramThrottlenumberThrottle URL writes in milliseconds-
paramDebouncenumberDebounce URL writes in milliseconds-
openbooleanControlled open state (passthrough to component)-
defaultOpenbooleanDefault open state for uncontrolled usagefalse

On this page