Skip to main content

useDisclosure

useDisclosure is a hook that provides all the tools you need to create a disclosure widget. Disclosure widgets are used to show or hide content. This hook provides the state and functions to control the visibility of the content.

Usage

Live Editor
function Demo() {
  const { isOpen, onOpen, onClose } = useDisclosure();

  return (
    <>
      <button onClick={onOpen}>Open</button>
      <button onClick={onClose}>Close</button>
      <p>{isOpen ? "Open" : "Close"}</p>
    </>
  );
};

Result
Loading...

API

UseDisclosureProps

PropertyDescriptionTypeDefaultValue
isOpenWhether the disclosure is open, if passed, it will be controlledboolean-
defaultOpendefault open stateboolean-
onCloseCallback when disclosure is closed() => void-
onOpenCallback when disclosure is opened() => void-
onChangeCallback when disclosure is changed(isOpen: boolean | undefined) => void-

useDisclosure

Returns

{ isOpen: boolean; onOpen: () => void; onClose: () => void; onOpenChange: () => void; isControlled: boolean; }

Arguments

ArgumentDescriptionTypeDefaultValue
props-UseDisclosureProps | undefined-