diff --git a/src/contexts/UIStateContext.tsx b/src/contexts/UIStateContext.tsx index 6aeca64..13645c4 100644 --- a/src/contexts/UIStateContext.tsx +++ b/src/contexts/UIStateContext.tsx @@ -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( diff --git a/src/hooks/useScrollPersistence.ts b/src/hooks/useScrollPersistence.ts index 9033cac..eb9c46b 100644 --- a/src/hooks/useScrollPersistence.ts +++ b/src/hooks/useScrollPersistence.ts @@ -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]); };