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

242
Views
how to use firebase.database().transaction() method efficiently in expo react native?

I am trying to get the orderid that I have stored on the Realtime Database of Firebase. For getting the data I have been using the firebase.database().transaction() method to avoid use conflicts between realtime use.

All I am trying to do is that get the id to assign it to the current order, then increment it by +1, and then return it to the firebase again. But the problem is that whenever I try to assign that value through the transaction method, I get a null or undefined object.

It does increment the value stored on firebase, but doesn't give an appropriate value to assign to the order object.

So, what can I do to get this done more efficiently?

here's the code I have been using to get the job done:

await firebase.database().ref().child("Order_Id").transaction((value) = > {
  //Sending data to firebase to book the order 
  firebaseRef.child(value).set({
    Appliance_Name: item.title,
    Service_Requested: orderData.serviceType,
    Image: orderData.uploadedImage,
    User_Problem: orderData.problem,
    Location: orderData.latitude + " , " + orderData.longitude,
    Status: "Booked",
    Time: dateTime,
    Assign: ""
  });
  return value + 1;
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems that you want to write to two different nodes of your RTDB in a transaction mode: firebase.database().ref().child("Order_Id") and firebaseRef.child(value).

Therefore the transaction needs to apply on a common ancestor of these two nodes. As explained in the doc, the update function (i.e. (value) = > {} in your case) needs to takes the current state of the data (value) as an argument and returns the new desired state you would like to write.", i.e. the new value of the data tree for this common ancestor node.

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