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

96
Views
Display label if list is empty

I want to display a div layer if list if empty into React page. I tried this:

        {(() => {
          if (!ordersList && ordersList.length === 0) {
            return (
              <div className="alert alert-warning">No Orders found</div>
            )
          }
        })()}

But it's not working. What is the proper way to implement this?

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

0

If I understand you correctly, you want to conditionally render a div when ordersList (a variable/state that I presume is in your component) is empty. Then add this to your JSX returned by your component.

{!ordersList.length && <div className="alert alert-warning">No Orders found</div>}
about 4 years ago · Juan Pablo Isaza Report

0

The condition is incorrect. If list is empty, then !ordersList will be false. So, the <div> won't be rendered.

You may try this:

{(() => {
          if (!ordersList || ordersList.length === 0) {
            return (
              <div className="alert alert-warning">No Orders found</div>
            )
          }
        })()}

Or even simpler:

{
  (!ordersList || ordersList.length === 0) && 
  <div className="alert alert-warning">No Orders found</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!