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

132
Views
Calculate height and show ViewMore Content based on list items content in React js

I have a dynamic array which is coming from the server and i need to set viewMore link when the element height is greater than certain height. This viewMore content need to be shown like this.

<div id={`_message_detail_list${id}`}>
      <ul style={{ "max-height":  valListMaxHeight }}>{listItems}</ul>
      <div>
        {viewMoreText (here i need to add another condition to check height of ul is greater than some threshold)  && (
          <div>
            <a
              id={`_primaryAction_${id}`}
              href="#"
              data-key={id}
              onClick={this.handleClick}>
              {viewMoreText}
            </a>
          </div>

is it possible to calculate the height and show another element based on this height?

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

0

You can use a ref in comibination with clientHeight like so:

const ulElementRef = useRef(null);

const ulHeight = elementRef.current?.clientHeight;

//...

<ul ref={ulElementRef} style={{ "max-height":  valListMaxHeight }}>{listItems}</ul>

Then you can use ulHeight for your condition.

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!