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

134
Views
Collapsible list with a loadmore button to show all the items from this list

I am developing a collapsible list that only shows the first five items and a load more button at first, and when I click the load more button, the full list should be shown. I am using scrollHeight to determine this collapsible list's height and it works fine to show the first five items and the load more button, but after I click the load more button, the height of this collapsible list does not change and the remaining items cannot be displayed due to the height constraint. Does anyone have an idea how to fix it? Thank you so much, I really got stuck here for this whole day.

This is how this collapsible list looks like the collapsible list

This is the code of collapsible list

    const Collapsible = ({ showCard, loaded, children }) => {
      const collapsibleEl = useRef();
      const [scrollHeight, setscrollHeight] = useState();
    
      useEffect(() => {
        setscrollHeight(collapsibleEl.current.scrollHeight);
        console.log(collapsibleEl.current.scrollHeight);
      }, [loaded, showCard]);
      return (
        <>
          <div
            className={styles.collapsible}
            ref={collapsibleEl}
            style={
              showCard
                ? scrollHeight
                  ? { height: `${scrollHeight + 100}px` }
                  : { height: `${collapsibleEl.current.scrollHeight + 100}px` }
                : { height: "0px" }
            }
          >
            {children}
          </div>
        </>
      );
    };
    export default Collapsible;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have figured it out, all I need to do is to use settimeout.

like this, just give it a little time to get the scrollheight and then re render.

useEffect(() => {
    setTimeout(() => {
      setscrollHeight(collapsibleEl.current.scrollHeight);
    }, 300);
    console.log(collapsibleEl.current.scrollHeight);
  }, [showCard, loaded]);
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!