import { useCallback } from 'react';
import { useRouter } from 'next/router';
import { pageLinks } from '@/helpers/constants';

function useBackHistory() {
    const router = useRouter();

    const handleBack = useCallback(() => {
        window.history.length > 2 ? router.back() : router.push(pageLinks.home);
    }, [router]);

    return handleBack;
}

export { useBackHistory };
