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

196
Views
ReactJS : Child wont re-rendered when the parents state object changes

I have been trying to re-render a contact list inside a Carousel by changing the state object in the parent class. The first time the Cards are rendered just fine - but when I try to add a new contact and update the state object, the child wont render again.

I have confirmed that the state object is updated correctly (logged inside useEffect hook at the parent component).

I am using @trendyol-js/react-carousel component below.

          const [contacts, setContacts] = React.useState([...contactArrayFromDB]);

          <Carousel
            className="carosusel"
            {...settings}
            rightArrow={
              <ArrowForwardIcon
                className="rightArrow"
                sx={{ color: styles.color.green }}
              />
            }
            leftArrow={
              <ArrowBackIcon
                className="backArrow"
                sx={{ color: styles.color.green }}
              />
            }
          >
            {**contacts.map**((item, index) => (
              <span>
                {console.log("rendering card .." + index)}
                <ContactCard
                  key={item.id}
                  item={item}
                  styles={styles}
                  isEditContacts={true}
                />
              </span>
            ))}
          </Carousel>

When I update the state, the log "rendering card .." is displayed on the console which means, the map function executes correctly everytime the state is updated.

I followed all the solutions on SO that I could find:

  1. Passed the entire state object inside the key property of the child . It didn't work! I even passed a random number through item.id that I am passing to the key parameter now.
  2. Used a state object inside the Child. Makes no difference.
  3. When changing the state object at the parent, I made sure I clone it instead of directly changing the array elements. Still didn't work.

I couldn't find any solution to it. React experts, please suggest how I may fix this problem.

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

0

Finally after much research, it turns out that the @trendyol-js/react-carousel has a dynamic flag that must be set to TRUE to allow adding newer items into it. The official document doesn't talk about it. Maybe this will help someone if they face a similar issue with this react component.

<Carousel
  dynamic={true} ...>
   ... items here
</Carousel>
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!