Skip to content

useDisclosure

Hook that allows you to open and close a modal

state
necessary
test coverage
Last changed: last month

Installation

Library
CLI
Manual
typescript
import { useDisclosure } from '@siberiacancode/reactuse';

Usage

typescript
const { opened, open, close, toggle } = useDisclosure();
## Demo

Api

Parameters

NameTypeDefaultNote
initialValue?booleanfalseThe initial value of the component
options.onOpen?() => void-The callback function to be invoked on open
options.onClose?() => void-The callback function to be invoked on close

Returns

UseDisclosureReturn

Type declaration

typescript
export interface UseDisclosureOptions {
  /** The callback function to be invoked on close */
  onClose?: () => void;
  /** The callback function to be invoked on open */
  onOpen?: () => void;
}

export interface UseDisclosureReturn {
  /** The opened value */
  opened: boolean;
  /** Function to close the modal */
  close: () => void;
  /** Function to open the modal */
  open: () => void;
  /** Function to toggle the modal */
  toggle: () => void;
}

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.