sickdyd / react-search-autocomplete

A search box that filters the provided array of objects
https://sickdyd.github.io/react-search-autocomplete
MIT License
218 stars 82 forks source link

AutoComplete list is not working if type is not {id,name} #51

Closed choyzer closed 2 years ago

choyzer commented 2 years ago

Try to change the Type to:

type Item = {
        value: string;
        label: string;
    }

<ReactSearchAutocomplete<Item>/>

Put items with new format

 const items = [
        {
            value: "0",
            label: 'Cobol'
        }
    ]

The autoComplete is not working

sickdyd commented 2 years ago

@choyzer You will need also an id field. Try to set that one up and see if it works.

sickdyd commented 2 years ago

@choyzer Update: you actually have 2 problems:

  1. you need to add an id field for each element
  2. your item does not have the default search name field, this means that you will need to specify where to search, for example:
    
    type Item = {
    id: number
    value: string
    label: string
    }

<ReactSearchAutocomplete items={[ { id: 0, value: '0', label: 'Cobol' }, { id: 1, value: '1', label: 'Ciao' } ]} // with this you are telling Fuse to search in label // you can specify multiple fields too if you need fuseOptions={{ keys: ['label'] }} />