import { useRef, useEffect, useCallback } from "react";
function useBatchedScroll(currentScrollTop) {
  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) => {
    pendingScrollTopRef.current = newScrollTop;
  }, []);
  return { getScrollTop, setPendingScrollTop };
}
export {
  useBatchedScroll
};
