react-vite-demo

react and vite demo

git clone https://9o.is/git/react-vite-demo.git

Select.tsx

(502B)


      1 import { useId, memo } from "react"
      2 
      3 type SelectProps = {
      4     label: string
      5     name: string
      6     options: readonly string[]
      7 }
      8 
      9 export const Select = memo(({ label, name, options }: SelectProps) => {
     10     const id = useId()
     11 
     12     return (
     13         <>
     14             <label htmlFor={id}>{label}</label>
     15             <select id={id} name={name}>
     16             <option value="">Select...</option>
     17             {options.map(option => <option key={option}>{option}</option>)}
     18             </select>
     19         </>
     20     )
     21 })