Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!