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

167
Vistas
How to refresh cart if there is no product left?

I need to refresh my cart page everytime, when products.length is 0 but I can't figure out how to write that if condition, now it writes unreachable code. I think it is something simple, so I am here to ask.

 switch (action.type){ 
     case "REMOVE_PRODUCT":
      return products.filter((p) => p.id !== action.productId);
      if (products.length === 0) {
        window.location.reload();
      }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Well, you code is unreachable since it is after a return statement, so change it to something like this:

switch (action.type) { 
  case "REMOVE_PRODUCT":
    const data = products.filter((p) => p.id !== action.productId);
    if (data.length === 0) {
      window.location.reload();
    }
    return data;
}

Note: If you are using redux, as it seems, maybe is better to handle this logic in the component that uses the data instead of here.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are receiving code unreachable as you are returning before checking into the IF block.

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