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

184
Vistas
Why does my DBSearch function keep looping when pulling data from Firebase?

New to coding last month and I'm learning JS through React Native.

I've added a Firestore DB to pull data through to my app and put together a call-back function using the useState hook due to it being Async.

My issue is my DBSearch function is now looping infinitely.

Code below:

const [propertyData, setPropertyData] = React.useState(["Well, this is awkward..."])

const colRef = (listName) => collection(db, listName)


const dbSearch = (listName, callBackFuncHere) => {onSnapshot(colRef(listName), (snapshot) => {
    let newList = []
    snapshot.docs.forEach(doc => {
    newList.push({ ...doc.data(), id: doc.id }) // Pulls Object Data and runs for loop to assign to newList Array
     })
     
    callBackFuncHere(newList)
})};

function retFunc(newList){
  setPropertyData(newList)
  console.log('1')
}


dbSearch('propertyList', retFunc)

Is this an improper use for useState? and how should I change my dbSearch function to stop it continually looping?

Apologies if this has been asked a thousand times before, I'm unsure how to clearly articulate and search for my problem.

about 4 years ago · Juan Pablo Isaza
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