# useDisclosure (/docs/hooks/use-disclosure)





`useDisclosure` tracks an open/closed boolean and hands back `open`, `close` and `toggle`. Reach for it when a trigger of your own drives something that takes an `open` prop, such as [`Collapse`](/docs/collapse), without pulling in a whole disclosure component.

```tsx
import { useDisclosure } from '@42-central/ui-react';
import { Collapse } from '@42-central/ui-react/collapse';

const [opened, { toggle }] = useDisclosure();

<button aria-expanded={opened} aria-controls="details" onClick={toggle}>
  Details
</button>
<Collapse id="details" open={opened}>…</Collapse>
```

It is uncontrolled only: there's no `value` prop, the state is yours and lives in this hook. To give a component of your own the kit's `open` / `defaultOpen` / `onOpenChange` props, build it on [`useUncontrolled`](/docs/hooks/use-uncontrolled) instead.

## Usage [#usage]

The trigger sets `aria-expanded` and `aria-controls` itself, since `Collapse` only takes the boolean. `onOpen` and `onClose` fire on a real transition only: pressing `open()` while it's already open does nothing.

<Preview code="&#x22;const [opened, { open, close, toggle }] = useDisclosure(false, {\n  onOpen: () => setOpened((n) => n + 1),\n  onClose: () => setClosed((n) => n + 1),\n});\n\n<Button aria-expanded={opened} aria-controls=\&#x22;details\&#x22; onClick={toggle}>\n  Details\n</Button>\n<Button variant=\&#x22;light\&#x22; onClick={open}>open()</Button>\n<Button variant=\&#x22;light\&#x22; onClick={close}>close()</Button>\n\n<Collapse id=\&#x22;details\&#x22; open={opened}>…</Collapse>&#x22;">
  <DisclosureDemo />
</Preview>

The callbacks run in the handler, never inside a state updater, so Strict Mode's double-invoked updaters don't fire them twice.

## API [#api]

<TypeTable
  type="{
  initialOpen: { type: 'boolean', default: 'false', description: 'The state on the first render.' },
  'callbacks.onOpen': { type: '() => void', description: 'Called when the state changes to true.' },
  'callbacks.onClose': { type: '() => void', description: 'Called when the state changes to false.' },
}"
/>

Returns `[opened, { open, close, toggle }]`.

<TypeTable
  type="{
  opened: { type: 'boolean', required: true, description: 'The current state.' },
  open: { type: '() => void', required: true, description: 'Sets the state to true.' },
  close: { type: '() => void', required: true, description: 'Sets the state to false.' },
  toggle: { type: '() => void', required: true, description: 'Flips the state.' },
}"
/>

The handlers keep their identity across renders as long as `onOpen` and `onClose` do. Pass stable callbacks (`useCallback`, or functions defined outside the component) when a handler sits in an effect's dependency list.
