I'm having trouble implementing smooth scrolling to an element based on React's useRef that will work in any of the modern browser without any lag in the animation. This seems hard and is why I'm asking for assistance.
Have tried to use the scrollIntoView({ behavior: 'smooth', block: 'start' }) which works nice in Google Chrome and Firefox, but Safari does not seem to work. Tried to install a polyfill (https://www.npmjs.com/package/smoothscroll-polyfill) for support in Safari and other browsers, but when testing on an Iphone 8 in Safari, its not good enough as the scroll animation lags.
Thinking on creating a util function called ScrollToElement which takes an element ref or something and try to animate it myself, but would like some help to get started, as I haven't really played with css animations that much.
Could some help me in the correct direction on solving this problem, so I can smoothly scroll to any div that works in any browsers?
const elementRef = useRef<HTMLDivElement>(null)
Utils function
export const scrollToElement = (element: HTMLDivElement) => {
}
I'm doing typescript btw.