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

229
Vistas
why is my react fragment throwing an unexpected token div error

I have an Iterator component inside my app which iterates over a given set of items and prints them to the page. Usually, the component works just fine. However, I've encountered a weird issue with React, where - despite the child components being wrapped in a Fragment component, React will still throw unexpected token div.

const Iterator = ({ items, children, ...props }) => (
    <div {...props}>
        { items.map((data, key) => (
            <Fragment key={key}>
                { children(data, key) }
            </Fragment>
        ))}
    </div>
);

// This "parent" element is the one that throws the error. 
<div className={styles.parent}>
    <Iterator items={items} className={styles.child}>{itemValue => (
        <Fragment>
            { itemValue?.type === "a" && (
                // Conditionally render a
            )}
            { itemValue?.type === "b" && (
                // Conditionally render b
            )}
        </Fragment>
    )}</Iterator>
</div>

Only when I remove one of the itemValue?.type === ... blocks does the code render as expected.

I may be missing something, but I can't put my finger on it. What's wrong here?

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