import { useEffect } from 'react' ; import { useTimeout } from './useTimeout' ; const useLongTouch = ( element , onLongTouch , touchDuration = 800 ) => { const { startTimeout , removeTimeout } = useTimeout ( onLongTouch , touchDuration ) ; useEffect ( ( ) => { if ( ! element ) { return ( ) => { } ; } const onTouchStart = ( event ) => { startTimeout ( ) ; } ; const onTouchEnd = ( event ) => { removeTimeout ( ) ; } ; element . addEventListener ( 'touchstart' , onTouchStart , false ) ; element . addEventListener ( 'touchend' , onTouchEnd , false ) ; return ( ) => { element . removeEventListener ( 'touchstart' , onTouchStart ) ; element . removeEventListener ( 'touchend' , onTouchEnd ) ; } ; } , [ onLongTouch , touchDuration ] ) ; } ; export { useLongTouch } ;