import { useEffect , useState } from 'react' ; import useIsInViewport , { CallbackRef , HookOptions } from 'use-is-in-viewport' ; function useClampedIsInViewport ( options ) { const [ isInViewport , ... etc ] = useIsInViewport ( options ) ; const [ wasInViewportAtleastOnce , setWasInViewportAtleastOnce ] = useState ( isInViewport ) ; useEffect ( ( ) => { setWasInViewportAtleastOnce ( ( prev ) => { if ( ! prev ) { return isInViewport ; } return prev ; } ) ; } , [ isInViewport ] ) ; return [ wasInViewportAtleastOnce , ... etc ] ; } export default useClampedIsInViewport ;