import { useContext , useEffect , useRef } from 'react' ; import { SelectListContext } from '../contexts' ; param scrollIntoView export function useScrollIntoView ( scrollIntoView = true ) { const targetElementRef = useRef ( null ) ; const { scrollElmRef } = useContext ( SelectListContext ) ; useEffect ( ( ) => { const targetElm = targetElementRef . current ; const scrollElm = scrollElmRef ?. current ; if ( scrollIntoView && targetElm && scrollElm && scrollElm . scrollHeight > scrollElm . clientHeight && scrollElm . scrollTop + scrollElm . clientHeight < targetElm . offsetTop + targetElm . clientHeight ) { scrollElm . scrollTop = targetElm . offsetTop ; } } , [ scrollIntoView ] ) ; return targetElementRef ; }