Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda