UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

22 lines (19 loc) 645 B
import { useEffect, useRef } from 'react'; import { useLocation } from 'react-router'; /** * A hook to use inside the component passed to FallbackComponent * of react-error-boundary. It resets the error boundary state whenever * the location changes * @param {Function} resetErrorBoundary */ export const useResetErrorBoundaryOnLocationChange = ( resetErrorBoundary: () => void ) => { const { pathname } = useLocation(); const originalPathname = useRef(pathname); useEffect(() => { if (pathname !== originalPathname.current) { resetErrorBoundary(); } }, [pathname, resetErrorBoundary]); };