useScrollTo.js

import { useEffect } from 'react';
import useScrollPosition from './useScrollPosition';
import useStickyState from './useStickyState';

export default function useScrollTo(params) {
  const { scrollTop = 0, stickStateName = null, elementRef = null, dependencies = [], delay = 0 } = params;
  useScrollPosition(elementRef);
  const [scroll] = useStickyState(stickStateName, null);

  useEffect(() => {
    setTimeout(() => {
      window.scrollTo({
        top: scroll?.top || scrollTop,
        behavior: 'smooth'
      });
    }, delay);
  }, dependencies);
}