Files
admin/packages/hooks/src/useDisclosure/Readme.md
T
2026-06-25 15:53:49 +03:00

1.4 KiB

useDisclosure

Manages a boolean open/closed state — useful for modals, drawers, dropdowns, and any show/hide UI pattern.

Signature

function useDisclosure(initial?: boolean): UseDisclosureControl;
Parameter Type Default Description
initial boolean false Initial open/closed state

Returns

interface UseDisclosureControl {
  isOpen: boolean;
  open: () => void;
  close: () => void;
  toggle: () => void;
}
Property Type Description
isOpen boolean Current open/closed state
open () => void Sets isOpen to true
close () => void Sets isOpen to false
toggle () => void Flips the current state

Usage

function ConfirmDialog() {
  const { isOpen, open, close } = useDisclosure();

  return (
    <>
      <button onClick={open}>Delete account</button>
      <Dialog open={isOpen} onClose={close}>
        <p>Are you sure?</p>
        <button onClick={close}>Cancel</button>
      </Dialog>
    </>
  );
}

Notes

  • open, close, and toggle are stable references (useCallback) and safe to pass as props without causing unnecessary re-renders.
  • Client-only ('use client').