Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda