import React, { useCallback, useEffect, useRef } from "react";

export default function useScrollTo() {
  const scrollTo = useRef();

  const scrollTop = useCallback(() => {
    if (scrollTo && scrollTo.current) {
      scrollTo.current({ position: { y: 0 }, animate: true });
    }
  }, []);

  const getScrollTo = useCallback((cbScrollTo) => {
    scrollTo.current = cbScrollTo;
  }, []);

  useEffect(() => {
    scrollTop();
  }, []);

  return { getScrollTo, scrollTop };
}
