nextjs-demo

next.js demo using react 19 rc

git clone https://9o.is/git/nextjs-demo.git

ComboBox.tsx

(699B)


      1 import { isPromise } from "@/lib"
      2 import { useId, memo, use } from "react"
      3 
      4 export type ComboBoxProps = {
      5     label: string
      6     name: string
      7     options: string[] | Promise<string[]>
      8   }
      9 
     10 export const ComboBox = memo(({ label, name, options }: ComboBoxProps) => {
     11     const opts = isPromise(options) ? use(options) : options
     12     const inputId = useId()
     13     const datalistId = useId()
     14 
     15     return (
     16         <>
     17             <label htmlFor={inputId}>{label}</label>
     18             <input id={inputId} name={name} type="text" list={datalistId} />
     19             <datalist id={datalistId}>
     20                 {opts.map(option => <option key={option} value={option} />)}
     21             </datalist>
     22         </>
     23     )
     24 })