import React from 'react' ; import { useEffect , EffectCallback , DependencyList , useState } from 'react' ; import { Options } from './options' ; import useThrottleFn from './useThrottleFn' ; import useUpdateEffect from './useUpdateEffect' ; function useThrottleEffect ( effect , deps ? , options ? ) { const [ flag , setFlag ] = useState ( { } ) ; const { run , cancel } = useThrottleFn ( ( ) => { setFlag ( { } ) ; } , options ) ; useEffect ( ( ) => { return run ( ) ; } , deps ) ; React . useEffect ( cancel , [ ] ) ; useUpdateEffect ( effect , [ flag ] ) ; } export default useThrottleEffect ;