import { useEffect, useRef } from 'react';

function useChangeEffect(fn, deps) {
  const statusRef = useRef(false);
  useEffect(() => {
    if (!statusRef.current) {
      return null;
    }
    const destory = fn();
    return () => {
      destory && destory();
    };
  }, [...deps]);

  useEffect(() => {
    statusRef.current = true;
  }, []);
}

export default useChangeEffect;
