import React, { useState, useEffect, useRef } from 'react'; import styles from './Dropdown.module.css'; export default function DropDown({ value, options = [], onChange }) { const [showMenu, setShowMenu] = useState(false); const ref = useRef(); function handleShowMenu() { setShowMenu(state => !state); } function handleSelect(value, e) { e.stopPropagation(); setShowMenu(false); onChange(value); } useEffect(() => { function hideMenu(e) { if (!ref.current.contains(e.target)) { setShowMenu(false); } } document.body.addEventListener('click', hideMenu); return () => { document.body.removeEventListener('click', hideMenu); }; }, [ref]); return (