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

160
Views
How can I add multiple conditions in react?

I have button Description. When clicked description is displayed. Now I want to add Read more/less on description.

With the belpw code, I do not see button Description, description is displayed directly

Flow- Display button-> On click-> Show 200 character text (With Read more option)

  const [readMore, setReadMore] = useState(false);


  const [displaydescription, setDisplayDescription] = useState(false);
  const clickHandler = () => {
    setDisplayDescription(true);
  };

 <p>
          {displaydescription || readMore
            ? description
            : `${description.substring(0, 200)}`}
        </p>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You have to change your code to first display description and then in second condition to verify if you want to show the full text like this:

const [readMore, setReadMore] = useState(false);
const [displaydescription, setDisplayDescription] = useState(false);
const clickHandler = () => {
    setDisplayDescription(true);
};

 <p>
    {displaydescription 
       ? (
            readMore
               ? description
               : `${description.substring(0, 200)
         )
       : null}`
    }
 </p>

about 4 years ago · Juan Pablo Isaza Report

0

The syntax to add a condition in React jsx is {condition && } so you could try

{ description && !readmore 
  <p> `${description.substring(0, 200)}` <p>
}
{ description && readmore 
  <p> `${description}` <p>
}   
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!