/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import { useRef, useEffect, useCallback } from 'react'; /** * @plan PLAN-20251215-OLDUI-SCROLL.P05 * @requirement REQ-456.4 */ export function useBatchedScroll(currentScrollTop: number) { const pendingScrollTopRef = useRef(null); const currentScrollTopRef = useRef(currentScrollTop); useEffect(() => { currentScrollTopRef.current = currentScrollTop; pendingScrollTopRef.current = null; }); const getScrollTop = useCallback( () => pendingScrollTopRef.current ?? currentScrollTopRef.current, [], ); const setPendingScrollTop = useCallback((newScrollTop: number) => { pendingScrollTopRef.current = newScrollTop; }, []); return { getScrollTop, setPendingScrollTop }; }