DEV Community

Discussion on: Simple search form in REACT using hooks 🔎.

 
clarity89 profile image
Alex K.

For your specific case you can do like this:

const results = searchTerm && searchTerm2 ?
  people.filter(person =>
    person.name.toLowerCase().includes(searchTerm.toLocaleLowerCase()) &&
    person.address.toLowerCase().includes(searchTerm2.toLocaleLowerCase())
  ) : people

However, note that the filter won't be applied unless both search terms are present.

Thread Thread
 
aa_ziz profile image
Ahmed Aziz

Yah but that is exactly what i don't want. I want that the user can choose one of the filters or both of them in the sametime

Thread Thread
 
luxer066 profile image
Lucas Canavesio

Hello! In the end you found the solution?