Merge pull request 'refactor: Optimize scroll position management to prevent unnecessary updates' (#24) from refactor into main

Reviewed-on: #24
This commit is contained in:
rov 2026-03-28 15:43:54 -03:00
commit 9d10556a4e
2 changed files with 9 additions and 5 deletions

View File

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

View File

@ -15,5 +15,6 @@ export const useScrollPersistence = (key: string) => {
return () => { return () => {
setScrollPosition(key, window.scrollY); 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]);
}; };