sickdyd / react-search-autocomplete

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

Cannot read properties of undefined (reading 'length') #102

Closed quocbahuynh closed 1 year ago

quocbahuynh commented 1 year ago

Describe the bug I have received a bug when selecting the item.

sickdyd commented 1 year ago

Can you give more details about the issue?

How to reproduce it?

Can you make a codesandbox with an example, please?

coder-raghu commented 1 year ago

Add and check resultStringKeyName="title" // String to display in the results Its working for me

sickdyd commented 1 year ago

Just to clarify for other users as well. By default resultStringKeyName is name, but if your items are a list such as (this objects do not have the name key):

 const items = [
   {
     id: 0,
     title: 'Titanic',
     description: 'A movie about love'
   },
   {
     id: 1,
     title: 'Dead Poets Society',
     description: 'A movie about poetry and the meaning of life'
   }
 ]

You will need to use one of the 3 keys id, title or description. This will be the value displayed in the results. If you try to use a key that does not exist, the error will appear. I will try to make a better descriptive error.