Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
I want to change the image I am using whenever the product is added to cart

I am using this right now, need to add a condition in such a way that whenever the getCartCount is 0 it should show image as bag_empty instead of bag and when the cart count is more than 0 it should show bag

<Badge count={getCartCount()}>
  <img
   className="bag__img"
   src={bag}
   alt=""
   onClick={user ? handleOpenBag : handleDynamicLink}
   onMouseOver={() => setbag(hoverbag)}
   onMouseOut={() => setbag(cart)}
 />
</Badge>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use a ternary operator like below, assuming that you have your empty bag image in your public folder.

<Badge count={getCartCount()}>
    <img
      className="bag__img"
      src={getCartCount()>0 ? bag : "/emty-bag-goes-here.png"}
      alt=""
      onClick={user ? handleOpenBag : handleDynamicLink}
      onMouseOver={() => setbag(hoverbag)}
      onMouseOut={() => setbag(cart)}
    />
</Badge>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda