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

95
Views
Ensure a component is rendered after DOM update

I have a ScrollBar that receives the CardsContainer as a ref in order to be able to display some HTML elements under it that allow for some custom scroll behavior.

The issue is, even if the state is updated and the cards are rerendered, the ScrollBar will still receive the old node because the node is creating while ScrollBar is rendered. How could I get around this?

  return (
        <div>
            <CardsContainer ref={nodeRef}>
              {cards.map((card, index) => (
                <Card
                  {...card}
                  index={index}
                  onClickDismiss={handleDismiss}
                />
              ))}
            </CardsContainer>
            <ScrollBar container={nodeRef} />
          </>
        </div>
      )

where

  const handleDismiss = (index: number) => {
    setCards([...cards.filter((c, i) => i !== index)])
  }

P.S. As requested, code of a button click event handler inside ScrollBar:

  const onClickRightArrow = () => {
    isArrowScroll.current = true
    if (activeIndex < container.children.length - 1) {
      container.children[activeIndex + 1].scrollIntoView({
        behavior: 'smooth',
        block: 'nearest',
        inline: 'center',
      })
      setActiveIndex(activeIndex + 1)
    }
  }
about 4 years ago · Santiago Gelvez
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!