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 947 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useResetErrorBoundaryOnLocationChange = void 0; const react_1 = require("react"); const useLocation_1 = require("./useLocation.cjs"); /** * 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 */ const useResetErrorBoundaryOnLocationChange = (resetErrorBoundary) => { const { pathname } = (0, useLocation_1.useLocation)(); const originalPathname = (0, react_1.useRef)(pathname); (0, react_1.useEffect)(() => { if (pathname !== originalPathname.current) { resetErrorBoundary(); } }, [pathname, resetErrorBoundary]); }; exports.useResetErrorBoundaryOnLocationChange = useResetErrorBoundaryOnLocationChange; //# sourceMappingURL=useResetErrorBoundaryOnLocationChange.js.map