import { useRef , useEffect , EffectCallback , useMemo } from 'react' ; note export const useImmediatelyEffect = < T extends Array < any > > ( callback , deps ? ) => { const unsubscribeRef = useRef < ReturnType < EffectCallback > > ( undefined ) ; unsubscribeRef . current = useMemo ( ( ) => { const unsubscribe = unsubscribeRef . current ; unsubscribeRef . current = undefined ; unsubscribe ?. ( ) ; return callback ( ) ; } , deps ) ; useEffect ( ( ) => ( ) => { const unsubscribe = unsubscribeRef . current ; unsubscribeRef . current = undefined ; unsubscribe ?. ( ) ; } , [ ] ) ; } ;