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

110
Views
Borrar datos antiguos sobre la representación de datos de firebase reaccionar nativo

Estoy tratando de obtener datos de firebase pero obtengo datos duplicados en la aplicación. Borro el estado de los pedidos antes de buscarlos y luego combino todos los pedidos de diferentes clientes, pero el problema es que obtengo el anterior. pedidos y ant. pedidos + nuevos pedidos todo combinado. Lo que quiero anterior. pedido + pedido nuevo solamente.

 useEffect(() => { let customerList1 = []; const unsubscribe = firebase .database() .ref(`/serviceProvider/${user1.uid}/franchise/customers`) .orderByKey() .on("value", (snapshot) => { customerList1.push(snapshot?.val()); setCustomerList(customerList1); // setCustomerList(snapshot.val()); }); setShowloading(false); return unsubscribe; }, [user1.uid]); useEffect(() => { const innerSubscriptions = []; // let orderList1 = []; if (customerList) { setOrders([]); // <-- clear orders Object.values(customerList).forEach((customer) => { if (customer) { Object.values(customer).forEach((id) => { const unsubscribe = firebase .database() .ref(`/orders/${id}`) .orderByKey() .on("value", (snapshot, key) => { // Grab all orders from the customers and merge const order = snapshot?.val(); // setOrders([...orders, order]); // realtime but gets only last customerList orders setOrders((orders) => [...orders, order]); // realtime all orders but reapeated the list and new orders // setOrders((orders) => { // return [...orders, order] // }); setShowloading(false); }); innerSubscriptions.push(unsubscribe); }); } }); } return () => { innerSubscriptions.forEach((unsubscribe) => unsubscribe); }; }, [customerList]);
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!