mobx-react-routing
Version:
MobX react-router-dom integration
17 lines (16 loc) • 600 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { observer } from 'mobx-react-lite';
const DefaultFallback = () => null;
export function withRouteBlocker(router, Component, Fallback = DefaultFallback) {
const WrappedComponent = observer((props) => {
if (router.blocked)
return _jsx(Fallback, {});
return _jsx(Component, { ...props });
});
if (process.env.NODE_ENV !== 'production') {
Object.assign(WrappedComponent, {
displayName: `WithRouteBlocker(${Component.name || 'Unknown'})`,
});
}
return WrappedComponent;
}