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

168
Visualizações
Adding multiple conditions in a single if statement

I'm using react and i want to map a component only when all my conditions are true, but there are 4 conditions and i don't want to use nested if statements

I tried this and it works, but i just think is ugly and not a good practice:

{posts.map((post, i) => {
              if (
                post.author &&
                post.story_title &&
                post.story_url &&
                post.created_at
              ) {
                return <Card key={i} post={post} />;
              } else {
                return null;
              }

I also tried this and it seems to work, but i'm not sure because when i log the variable isValidPost i get a date and not a boolean false or true:

 {posts.map((post, i) => {
              let isValidPost =
                post.author &&
                post.story_title &&
                post.story_url &&
                post.created_at;
              console.log(isValidPost);
              if (isValidPost) {
                return <Card key={i} post={post} />;
              } else {
                return null;
              }

is there a better way to make this validation?

about 4 years ago · Juan Pablo Isaza
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