// DropdownContext.tsx import React, { createContext, useContext, useState, useCallback, ReactNode } from 'react'; interface DropdownContextValue { openDropdownId: string | null; openDropdown: (id: string) => void; closeDropdown: (id: string) => void; closeAll: () => void; } const DropdownContext = createContext(null); export const DropdownProvider: React.FC<{ children: ReactNode }> = ({ children }) => { const [openDropdownId, setOpenDropdownId] = useState(null); const openDropdown = useCallback((id: string) => { setOpenDropdownId(id); }, []); const closeDropdown = useCallback((id: string) => { setOpenDropdownId((current) => (current === id ? null : current)); }, []); const closeAll = useCallback(() => { setOpenDropdownId(null); }, []); return ( {children} ); }; export const useDropdownContext = () => useContext(DropdownContext);