sickdyd/react-search-autocomplete

Cannot read properties of undefined (reading 'length')

Closed this issue · 3 comments

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

Can you give more details about the issue?

How to reproduce it?

Can you make a codesandbox with an example, please?

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

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.