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

131
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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