/* eslint-disable react-hooks/exhaustive-deps */ import { useEffect, useState } from "react"; import ChevronDownIcon from "./icons/ChevronDownIcon"; import { useClickAway } from "@uidotdev/usehooks"; import CheckIcon from "./icons/CheckIcon"; interface Props { required?: boolean; defaultOption?: string; options: string[]; onSelect: (option: string) => void; } function Select3({ required, defaultOption, options, onSelect }: Props) { const [showOptions, setShowOptions] = useState(false); const [selectedOption, setSelectedOption] = useState(); const ref = useClickAway(() => { setShowOptions(false); }); function handleSelect(option: string) { setSelectedOption(option); onSelect(option); setShowOptions(false); } useEffect(() => { if (!defaultOption) return; handleSelect(defaultOption); }, [defaultOption]); return (
setShowOptions((prev) => !prev)} >
{showOptions && (
{options.map((option, index) => ( ))}
)}
); } export default Select3;