Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

526
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda