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

192
Views
¿Cómo eliminar artículos del carrito?

Soy nuevo en JavaScript y tengo un problema. No entiendo cómo crear un evento que elimine elementos de la página del carrito. Creé addCartEvent pero no sé cómo eliminar productos. Ya creé el componente del botón menos. En el proyecto estoy usando Firebase.

Aquí hay un código de la página del carrito:

 export default function CartPage() { const { user, loading } = useAuth(); const { data } = useCart(); const cartLength = Object.keys(data).reduce((a, b) => a + data[b].length, 0); const cartItems = cartLength > 0 ? Object.keys(data) .map((item) => { return data[item].map((size) => { return { name: item, size, }; }); }) .flat(1) : []; const sizeCount = cartItems.reduce( (acc, value) => ({ ...acc, [value.name + '__size__' + value.size]: (acc[value.name + '__size__' + value.size] || 0) + 1, }), {} ); const cartItemsArray = [ ...new Set( cartItems.filter( (v, i, a) => a.findIndex((t) => t.name === v.name && t.size === v.size) === i ) ), ].map((item) => { return { ...item, count: sizeCount[item.name + '__size__' + item.size] }; }); const addCartEvent = (id, size) => { const newCart = size ? { ...data, [id]: data.hasOwnProperty(id) ? [...data[id], size] : [size], } : { ...data, [id]: data.hasOwnProperty(id) ? [...data[id], '-'] : ['-'], }; addToCart(newCart); }; const router = useRouter(); }

Y código de firebase/product.js:

 import { auth, db } from '../config/firebase'; function addToCart(newCart) { const currentUser = auth.currentUser.uid; return db.collection('Users').doc(currentUser).update({ cart: newCart, }); } export { addToCart };

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!