export default function debounce ( func , wait ) { let timeout = null ; let later = null ; const debouncedFunction = ( ... args ) => { later = ( ) => { timeout = null ; func ( ... args ) ; } ; clearTimeout ( timeout ) ; timeout = setTimeout ( later , wait ) ; } ; const cancel = ( ) => { if ( timeout !== null ) { clearTimeout ( timeout ) ; later ( ) ; } } ; return [ debouncedFunction , cancel ] ; }