import { useState } from "react"; import React from "react"; export interface DropDownOption { label: string; value: T; } export function useDropDown(options: DropDownOption[]) { const [selectedLabel, setSelectedLabel] = useState(options[0].label); return { options: options.map(x => x.label), value: selectedLabel, onChange(e: React.ChangeEvent) { setSelectedLabel(e.target.value); }, get selected() { return options.find(x => x.label === selectedLabel)?.value ?? options[0].value; } } } export interface DropDownProps { options: string[], value: string, onChange(e: React.ChangeEvent): void; } export function DropDown({options, value, onChange}: DropDownProps) { return ( ); }