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

243
Visualizações
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 Respostas
Responde à pergunta

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 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