DEV Community

Discussion on: How to build an image carousel with React

willamesoares profile image
Will Soares Author

Hello mujeex,

So, considering that useEffect should be the equivalent of componentDidMount, that is sort of how I would approach the scenario you described. The only difference is that in my opinion it makes sense to continuously loop the carousel, so setInterval would make more sense than setTimeout (which would trigger only once after the component mounts).

Also, make sure that you clear up after yourself, meaning that when you set an interval after mounting a component you better clear that before the component unmounts :)

Thread Thread
mujeex profile image
mujeex

Amazing! It worked like a charm. Thanks a lot, Will. I am really looking forward to your reusable carousel.