mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-21 13:19:22 +01:00
15 lines
366 B
JavaScript
15 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 : () => {};
|