September 2024
Intermediate to advanced
174 pages
3h 44m
English
As we’ve seen, you can use hooks within hooks as long as you follow the rules of hooks every step of the way. That extends to custom hooks as well.
In this section, you’ll add a new feature to Carousel: the ability to auto-advance the slideIndex on Carousel every few seconds with a timer. To keep useSlideIndex from becoming too big and complex, the timer logic will be encapsulated in a new custom hook used within useSlideIndex.
But before getting to the implementation, let’s write some tests.
Testing code that uses timers poses an obvious problem: how do you write tests that give you instant feedback if you need to wait for timers to resolve? The answer is, you don’t. Modern test frameworks have ...
Read now
Unlock full access