import { useEffect } from 'react';
import qs from 'qs';
import { isEmptyObject } from 'utils/utils';
import { useHash } from 'components/easyUse';

export default function useHashCallback(callback: (id: number | null, param: object) => void) {
  const hash = useHash();

  useEffect(() => {
    const hashCallback = qs.parse(hash.slice(1));

    if (!isEmptyObject(hashCallback)) {
      callback(null, hashCallback);
    }
  }, [hash]);

  return null;
}
