mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-08 09:07:44 +03:00
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 : () => {};
|