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

96
Views
Restablecer valor en la base de datos de Firebase

Tengo un problema con base de fuego. Todo está bien y funciona, pero si llamo demasiado a la función onBuyHandler (si hago clic demasiadas veces en el botón de compra (porque llama a esta función)), el valor se restablece y se configura desde 1 y no sé por qué. ¿Alguien me puede ayudar?

Esta función:

 const onBuyHandler = (event) => { const db = ref(database); const foodRef = ref( database, `users/${user.uid}/items/${props.room}/${props.item.name}` ); get(foodRef) .then((snapshot) => { if (snapshot.hasChild('name')) { runTransaction(foodRef, (data) => { if (data) { data.amount++; invCtx.setItems((prevState) => { const newState = { ...prevState }; newState[props.item.name] = data; return { ...newState }; }); } return data; }); } else { set(foodRef, { name: props.item.name, amount: 1, }); invCtx.setItems((prevState) => { const newState = { ...prevState }; newState[props.item.name] = { name: props.item.name, amount: 1, }; return newState; }); } }) .catch((error) => { console.log(error); }); };
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!