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:
690 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import { useEffect } from 'react';
|
---|
| 2 | import { off, on } from './misc/util';
|
---|
| 3 | var usePageLeave = function (onPageLeave, args) {
|
---|
| 4 | if (args === void 0) { args = []; }
|
---|
| 5 | useEffect(function () {
|
---|
| 6 | if (!onPageLeave) {
|
---|
| 7 | return;
|
---|
| 8 | }
|
---|
| 9 | var handler = function (event) {
|
---|
| 10 | event = event ? event : window.event;
|
---|
| 11 | var from = event.relatedTarget || event.toElement;
|
---|
| 12 | if (!from || from.nodeName === 'HTML') {
|
---|
| 13 | onPageLeave();
|
---|
| 14 | }
|
---|
| 15 | };
|
---|
| 16 | on(document, 'mouseout', handler);
|
---|
| 17 | return function () {
|
---|
| 18 | off(document, 'mouseout', handler);
|
---|
| 19 | };
|
---|
| 20 | }, args);
|
---|
| 21 | };
|
---|
| 22 | export default usePageLeave;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.