import { useState } from 'react' import { basicMatch, byLengthAsc, extendedMatch, type UseFzfOptions, FzfHighlight, useFzf } from 'react-fzf' import { names } from '../utils/data' import { Example } from '../utils/Example' function nameToLastname(name: string) { return name.split(' ')[1] ?? '' } export function WithOptions() { const [query, setQuery] = useState('') const [casing, setCasing] = useState('smart-case') const [forward, setForward] = useState(true) const [fuzzy, setFuzzy] = useState('v2') const [lastNameOnly, setLastNameOnly] = useState(false) const [lengthTiebreaker, setLengthTiebreaker] = useState(false) const [limit, setLimit] = useState(20) const [normalize, setNormalize] = useState(true) const [sort, setSort] = useState(true) const [useExtendedMatch, setUseExtendedMatch] = useState(false) const { getFzfHighlightProps, results } = useFzf({ casing, forward, fuzzy, items: names, itemToString: lastNameOnly ? nameToLastname : undefined, limit, match: useExtendedMatch ? extendedMatch : basicMatch, normalize, query, sort, tiebreakers: lengthTiebreaker ? [byLengthAsc] : [], }) return ( } >
    {names.map((name) => (
  • {name}
  • ))}
    {results.map((item, index) => (
  • ))}
) } type Casing = NonNullable['casing']> type Fuzzy = NonNullable['fuzzy']>