Vidly app pagination bug

Hi there,if I have 3 pages with 4-4-1 movies and if I go to third page and delete that single movie it won’t change to second page and if I delete all 4 movies on second page all movies disappear.
Did anyone notice this and fixed it?

useEffect(() => {
   const pagesCount = Math.ceil(totalMovies / pageSize);
    if (currentPage > pagesCount) setCurrentPage(pagesCount);
 }, [currentPage, totalMovies, pagesCount]);

try add this in your code