Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

531
Visualizações
How to filter (search) data from Firebase - React Native

I would like to filter my search term against all the data from the databse.

I think the logic would be: capitalize both searchterm and data, then compare searchterm with each field from the data. Then setData() to that filtered search.

The const Data is used in a flatlist so my filtered data will be shown here.

Thank you for any assistance.

My code:

const SearchFeed = (searchterm) => {


  const q = query(PostsCollectionRef, orderBy('timestamp', 'desc'));

  onSnapshot(q, querySnapshot => {

    const id = querySnapshot.docs.map(doc =>
      ({
        id: doc.id,
        timestamp: doc.data().timestamp,
        postID: doc.data().PostID,
        title: doc.data().status + " " + doc.data().Type,
        status: doc.data().status,
        location: doc.data().location,
        type: doc.data().Type,
        injured: doc.data().Injured,
        collar: doc.data().Collar,
        color: doc.data().Colour,
        username: doc.data().username[0],
        description: doc.data().Description,
        imagesrc: doc.data().picture
      }))

//need to capitalize searchterm
//need to capitalize filter value
//eg id.filter((capitalize(val) => val.type == capitalize(searchterm)

    const Animal = id.filter((val) => val.type == searchterm)
    setData(Animal)
    console.log(Animal)
  });
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you have all the posts data on client already, you can use a package like Lunr to add full text search functionality in web app. You can use add() method to add data of all documents fetched and then search() to look for documents instead of using a filter().

Do note that you are fetching all the documents from Posts collection every time so that involves lots of read charges. You can algo try using Algolia (with Firebase Algolia Extension). This indexes all the documents added to Firestore in Algolia and then you can directly query data from Algolia based on the search term.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda