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

146
Views
ternory operator giving error when used to show or hide a div react js

i am trying to hide a div when it is in mobile view i am using a ternory operator and i am getting error i cannot compltely hide the div becase it already has a ternory operator inside it how can i achive this

 {this.state.hidediv?
               (<div className="livechat">): (<div className="livechat2">)
                 } //error here 
                 {this.state.hidecaht ? (
                   <>
                     <a
                       href="#"
                       className="close"
                       onClick={() => this.hidechat(true)}
                     ></a>
                     <Livechat id={this.state.liveid} />
                   </>
                 ) : null}
               </div>

livechat2 has css display:none so it wont show up

imgenter image description here

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

0

The issue is that you give an unclosed tag, try this:

<div className={this.state.hidediv ? "livechat" : "livechat2"}>
  {this.state.hidecaht &&
     <>
       <a
         href="#"
         className="close"
         onClick={() => this.hidechat(true)}
       ></a>
       <Livechat id={this.state.liveid} />
     </>
   }
</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!