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

238
Views
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 answers
Answer question

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 Report

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