refactor: Optimize scroll position management to prevent unnecessary updates #24

Merged
rov merged 1 commits from refactor into main 2026-03-28 15:43:55 -03:00
2 changed files with 9 additions and 5 deletions
Showing only changes of commit 9c70d60267 - Show all commits

View File

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

View File

@ -15,5 +15,6 @@ export const useScrollPersistence = (key: string) => {
return () => {
setScrollPosition(key, window.scrollY);
};
}, [key, setScrollPosition, scrollPositions]); // eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key, setScrollPosition]);
};