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

128
Views
JSX doesn't render on conditional render alongside with map function

I want to render a component based on a variable being true or false. At the moment the condition comes up as true but the component isn't rendering at all.

Here is my code:

<div className={styles.container}>
   {array.map(item => {
    router.query.slug != item ? <Component /> : null;
    })}
</div>

My console is returning true for the condition router.query.slug != item so what am I missing?

Thanks

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are missing to return the component from map function.

Here is the example that will match your problem:

Solution 1

<div className={styles.container}>
    {array.map(item => {
        return router.query.slug != item ? <Component /> : null;
    })}
</div>

Solution 2 with single line

<div className={styles.container}>
    {array.map(item => router.query.slug != item ? <Component /> : null)}
</div>

You can read about map function in here.

about 4 years ago · Juan Pablo Isaza Report

0

If you use the block syntax, you need to specify the return keyword. Learn more about arrow-function

Try this way.

Example:

<div className={styles.container}>
   {array.map(item => {
     return (router.query.slug != item ? <Component /> : null)
    })}
</div>
about 4 years ago · Juan Pablo Isaza Report
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!