import { useCombobox } from 'downshift' import { useState } from 'react' import { FzfHighlight, useFzf } from 'react-fzf' import { posts } from '../utils/data' import { Example } from '../utils/Example' function postToString(post: typeof posts[number] | null): string { return post?.title ?? '' } export function WithGenerics() { return } export function Combobox({ items, itemToString }: ComboboxProps) { const [query, setQuery] = useState('') const { getFzfHighlightProps, results } = useFzf({ items, itemToString, query, }) const { getInputProps, getItemProps, getLabelProps, getMenuProps, getToggleButtonProps, highlightedIndex, isOpen, selectedItem, } = useCombobox({ items: results, itemToString, onInputValueChange: ({ inputValue }) => { setQuery(inputValue ?? '') }, }) return (
    {posts.map((post) => (
  • {JSON.stringify(post)}
  • ))}
    {isOpen && results.map((item, index) => { const itemStr = itemToString(item) return (
  • ) })}
) } interface ComboboxProps { items: TItem[] itemToString: (item: TItem | null) => string }