Merge pull request 'refactor: Simplify useEffect dependencies in Chapter and UIStateContext components' (#26) from refactor into main

Reviewed-on: #26
This commit is contained in:
rov 2026-03-28 17:36:53 -03:00
commit 753c6b9068
2 changed files with 9 additions and 12 deletions

View File

@ -80,13 +80,10 @@ export const UIStateProvider = ({ children }: { children: ReactNode }) => {
}, []);
const setScrollPosition = useCallback((key: string, position: number) => {
setScrollPositions((prev) => {
if (prev[key] === position) return prev;
return {
...prev,
[key]: position,
};
});
setScrollPositions((prev) => ({
...prev,
[key]: position,
}));
}, []);
const value = useMemo(

View File

@ -35,12 +35,12 @@ const Chapter = () => {
if (currentPage === data.data?.contentImageKeys.length) {
mutate({ mangaContentId: chapterNumber });
}
}, [data, mutate, currentPage, chapterNumber, isLoading]);
}, [data, mutate, currentPage]);
/** Persist reading progress */
useEffect(() => {
setCurrentChapterPage(chapterNumber, currentPage);
}, [chapterNumber, currentPage, setCurrentChapterPage]);
}, [chapterNumber, currentPage]);
/** Restore stored page */
useEffect(() => {
@ -51,7 +51,7 @@ const Chapter = () => {
setVisibleCount(stored); // for infinite scroll
}
}
}, [isLoading, data?.data, chapterNumber, getCurrentChapterPage]);
}, [isLoading, data?.data]);
/** Infinite scroll observer */
useEffect(() => {
@ -90,7 +90,7 @@ const Chapter = () => {
imgs.forEach((img) => observer.observe(img));
return () => observer.disconnect();
}, [infiniteScroll]);
}, [infiniteScroll, visibleCount]);
useEffect(() => {
if (!data?.data) return;
@ -107,7 +107,7 @@ const Chapter = () => {
// Single page mode → scroll to top
window.scrollTo({ top: 0 });
}
}, [infiniteScroll, currentPage, data?.data]);
}, [infiniteScroll]);
if (!data?.data) {
return (