Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!