main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
889 bytes
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var react_1 = require("react");
|
---|
| 4 | var util_1 = require("./misc/util");
|
---|
| 5 | var useBeforeUnload = function (enabled, message) {
|
---|
| 6 | if (enabled === void 0) { enabled = true; }
|
---|
| 7 | var handler = react_1.useCallback(function (event) {
|
---|
| 8 | var finalEnabled = typeof enabled === 'function' ? enabled() : true;
|
---|
| 9 | if (!finalEnabled) {
|
---|
| 10 | return;
|
---|
| 11 | }
|
---|
| 12 | event.preventDefault();
|
---|
| 13 | if (message) {
|
---|
| 14 | event.returnValue = message;
|
---|
| 15 | }
|
---|
| 16 | return message;
|
---|
| 17 | }, [enabled, message]);
|
---|
| 18 | react_1.useEffect(function () {
|
---|
| 19 | if (!enabled) {
|
---|
| 20 | return;
|
---|
| 21 | }
|
---|
| 22 | util_1.on(window, 'beforeunload', handler);
|
---|
| 23 | return function () { return util_1.off(window, 'beforeunload', handler); };
|
---|
| 24 | }, [enabled, handler]);
|
---|
| 25 | };
|
---|
| 26 | exports.default = useBeforeUnload;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.