a list of items showing each for a specific time with different color infinitely

Viewed 31

so I want to show a list of product cards and every 5 seconds one of these cards has the main color and the rest have the same color.

I have rendered the cards with mapping the array.

since I have one main card at a time I create a new state (active index).

my solution for having such animation was to set an interval in the init(I mean the useEffect with out any dependency) of parent component and changes the active index and then in the useEffect with active index dependency I removed the interval and after a time out I set the interval again (to change active index).

but it does not behave the way I expected.

any help or idea would be appreciated. if you didn't understand the question comment below and if needed I would add the code to.

P.S. this repo can reproduce the situation i'm in and show you the overall of what I want to achive : repo

0 Answers
Related