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

169
Vistas
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 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