UNPKG

nextuiq

Version:

NextUIQ is a modern, lightweight, and developer-friendly UI component library for React and Next.js. Built with TypeScript and Tailwind CSS, it offers customizable, accessible, and performance-optimized components with built-in dark mode, theme customizat

29 lines (26 loc) 642 B
import { useState, useCallback } from 'react'; const useModal = ({ defaultOpen = false, onOpenChange } = {}) => { const [isOpen, setIsOpen] = useState(defaultOpen); const open = useCallback(() => { setIsOpen(true); onOpenChange?.(true); }, [onOpenChange]); const close = useCallback(() => { setIsOpen(false); onOpenChange?.(false); }, [onOpenChange]); const toggle = useCallback(() => { setIsOpen((prev) => { const newState = !prev; onOpenChange?.(newState); return newState; }); }, [onOpenChange]); return { isOpen, open, close, toggle }; }; export { useModal };