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

250
Vistas
Fragments should contain more than one child. EsLint Error. If Component

I currently have this code, but EsLint shows the following error: "Fragments must contain more than one child - otherwise there is no need for a fragment.". But I can't do an IF without wrapping the code in a React.Fragment. Is there another way to remove this error without allowing a lint rule?

return (
            <>
                {loading && (
                    <div className={classes.container}>
                        <img
                            alt="loading"
                            src={LoadingAnimation}
                            className={classes.img}
                        />
                    </div>
                )}
            </>
        );
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to return JSX inside the Fragment for instance:

Bad

    return (
    <>
    <div>
    {users.map(user => {
<p>{user}</p>
})}
    </div>
    </>
    )

Good

return (
<>
 <div>
{users.map(user => {
return <p>{user}</p>
})}
</div>
</>
)

so in your case I would do:

return (
            <>
                {loading ? (
                    <div className={classes.container}>
                        <img
                            alt="loading"
                            src={LoadingAnimation}
                            className={classes.img}
                        />
                    </div>
                ) : null}
            </>
        );
about 4 years ago · Juan Pablo Isaza Denunciar

0

This is a way to fix

return loading ? (
                    <div className={classes.container}>
                        <img
                            alt="loading"
                            src={LoadingAnimation}
                            className={classes.img}
                        />
                    </div>
                )
                : null;
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