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:
787 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 usePageLeave = function (onPageLeave, args) {
|
---|
| 6 | if (args === void 0) { args = []; }
|
---|
| 7 | react_1.useEffect(function () {
|
---|
| 8 | if (!onPageLeave) {
|
---|
| 9 | return;
|
---|
| 10 | }
|
---|
| 11 | var handler = function (event) {
|
---|
| 12 | event = event ? event : window.event;
|
---|
| 13 | var from = event.relatedTarget || event.toElement;
|
---|
| 14 | if (!from || from.nodeName === 'HTML') {
|
---|
| 15 | onPageLeave();
|
---|
| 16 | }
|
---|
| 17 | };
|
---|
| 18 | util_1.on(document, 'mouseout', handler);
|
---|
| 19 | return function () {
|
---|
| 20 | util_1.off(document, 'mouseout', handler);
|
---|
| 21 | };
|
---|
| 22 | }, args);
|
---|
| 23 | };
|
---|
| 24 | exports.default = usePageLeave;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.