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:
I couldn't find any solution to it. React experts, please suggest how I may fix this problem.
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>