I have the following component definition:
import { useRef } from 'react';
export default function useScroll() {
const ref = useRef(null)
const executeScroll = () => {
if (ref != null)
window.scrollTo(0, ref.current.offsetTop)
}
const htmlElementAttributes = { ref }
return [executeScroll, htmlElementAttributes]
}
The line window.scrollTo(0, ref.current.offsetTop)
throws the error. I have included if (ref != null)
check, but did not work. Any ideas?