import React from 'react' ; export default ( callback , buffer ) => { const calledRef = React . useRef < boolean > ( false ) ; const timeoutRef = React . useRef < number > ( null ) ; function cancelTrigger ( ) { window . clearTimeout ( timeoutRef . current ) ; } function trigger ( force ? ) { if ( ! calledRef . current || force === true ) { if ( callback ( ) === false ) { return ; } calledRef . current = true ; cancelTrigger ( ) ; timeoutRef . current = window . setTimeout ( ( ) => { calledRef . current = false ; } , buffer ) ; } else { cancelTrigger ( ) ; timeoutRef . current = window . setTimeout ( ( ) => { calledRef . current = false ; trigger ( ) ; } , buffer ) ; } } return [ trigger , ( ) => { calledRef . current = false ; cancelTrigger ( ) ; } , ] ; } ;