source: imaps-frontend/node_modules/react-use/esm/useBeforeUnload.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 797 bytes
RevLine 
[d565449]1import { useCallback, useEffect } from 'react';
2import { off, on } from './misc/util';
3var useBeforeUnload = function (enabled, message) {
4 if (enabled === void 0) { enabled = true; }
5 var handler = useCallback(function (event) {
6 var finalEnabled = typeof enabled === 'function' ? enabled() : true;
7 if (!finalEnabled) {
8 return;
9 }
10 event.preventDefault();
11 if (message) {
12 event.returnValue = message;
13 }
14 return message;
15 }, [enabled, message]);
16 useEffect(function () {
17 if (!enabled) {
18 return;
19 }
20 on(window, 'beforeunload', handler);
21 return function () { return off(window, 'beforeunload', handler); };
22 }, [enabled, handler]);
23};
24export default useBeforeUnload;
Note: See TracBrowser for help on using the repository browser.