UNPKG

daily-toolset

Version:

A lightweight, versatile collection of TypeScript utility functions for everyday development needs. Simplify and streamline your Node.js, React, and Next.js projects with a powerful suite of well-organized helpers for strings, arrays, dates, objects, and

30 lines (29 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDisclosure = useDisclosure; const react_1 = require("react"); /** * A custom React hook that manages the open/closed state of a component. * * @param defaultOpen - Initial open state (default is false). * @returns A tuple containing the current open state and an object with methods to open, close, and toggle the state. */ function useDisclosure(initialState = false, options) { const [open, setOpen] = (0, react_1.useState)(initialState); return [ open, { open: () => { var _a; setOpen(true); (_a = options === null || options === void 0 ? void 0 : options.onOpen) === null || _a === void 0 ? void 0 : _a.call(options); }, close: () => { var _a; setOpen(false); (_a = options === null || options === void 0 ? void 0 : options.onClose) === null || _a === void 0 ? void 0 : _a.call(options); }, toggle: () => setOpen(!open), }, ]; }