import { useEffect } from 'react';
export function useScroll(tableRef, bottomEndScrollOffset, onScrollEnd, isLoading) {
  const {
    scrollHeight,
    scrollTop,
    clientHeight
  } = tableRef.current || {};
  const elementPresent = scrollHeight && scrollTop && clientHeight;
  const isScrollToEnd = elementPresent && scrollHeight - scrollTop - clientHeight < bottomEndScrollOffset;
  const notEnoughForScroll = scrollHeight === clientHeight;
  useEffect(() => {
    if (isScrollToEnd || notEnoughForScroll) {
      onScrollEnd();
    }
  }, [scrollHeight, scrollTop, clientHeight]);
  useEffect(() => {
    if (!isLoading && (isScrollToEnd || notEnoughForScroll)) {
      onScrollEnd();
    }
  }, [isLoading]);
}