UNPKG

@modern-kit/react

Version:
23 lines (19 loc) 642 B
'use strict'; var utils = require('@modern-kit/utils'); var React = require('react'); function useBeforeUnload(enabled = true) { const enabledToUse = utils.isFunction(enabled) ? enabled() : enabled; React.useEffect(() => { if (!enabledToUse) return; const handleBeforeUnload = (event) => { event.preventDefault(); return event.returnValue = ""; }; window.addEventListener("beforeunload", handleBeforeUnload); return () => { window.removeEventListener("beforeunload", handleBeforeUnload); }; }, [enabledToUse]); } exports.useBeforeUnload = useBeforeUnload; //# sourceMappingURL=index.cjs.map