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

106
Visualizações
Display label if list is empty

I want to display a div layer if list if empty into React page. I tried this:

        {(() => {
          if (!ordersList && ordersList.length === 0) {
            return (
              <div className="alert alert-warning">No Orders found</div>
            )
          }
        })()}

But it's not working. What is the proper way to implement this?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If I understand you correctly, you want to conditionally render a div when ordersList (a variable/state that I presume is in your component) is empty. Then add this to your JSX returned by your component.

{!ordersList.length && <div className="alert alert-warning">No Orders found</div>}
about 4 years ago · Juan Pablo Isaza Relatório

0

The condition is incorrect. If list is empty, then !ordersList will be false. So, the <div> won't be rendered.

You may try this:

{(() => {
          if (!ordersList || ordersList.length === 0) {
            return (
              <div className="alert alert-warning">No Orders found</div>
            )
          }
        })()}

Or even simpler:

{
  (!ordersList || ordersList.length === 0) && 
  <div className="alert alert-warning">No Orders found</div>
}
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