mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-08 17:16:25 +01:00
7b246fc660
It shipped since Chrome 120 https://chromestatus.com/feature/4722261258928128
14 lines
366 B
JavaScript
14 lines
366 B
JavaScript
import { useEffect } from 'preact/hooks';
|
|
|
|
function useCloseWatcher(fn, deps = []) {
|
|
if (!fn || typeof fn !== 'function') return;
|
|
useEffect(() => {
|
|
const watcher = new CloseWatcher();
|
|
watcher.addEventListener('close', fn);
|
|
return () => {
|
|
watcher.destroy();
|
|
};
|
|
}, deps);
|
|
}
|
|
|
|
export default window.CloseWatcher ? useCloseWatcher : () => {};
|