mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-01 11:26:23 +02:00
add rowboat app
This commit is contained in:
parent
b83b5f8a07
commit
10f76ef49f
117 changed files with 25370 additions and 0 deletions
23
apps/rowboat/hooks/use-click-away.ts
Normal file
23
apps/rowboat/hooks/use-click-away.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { useEffect, RefObject } from 'react';
|
||||
|
||||
export function useClickAway(
|
||||
ref: RefObject<HTMLElement>,
|
||||
handler: (event: MouseEvent | TouchEvent) => void
|
||||
) {
|
||||
useEffect(() => {
|
||||
const listener = (event: MouseEvent | TouchEvent) => {
|
||||
if (!ref.current || ref.current.contains(event.target as Node)) {
|
||||
return;
|
||||
}
|
||||
handler(event);
|
||||
};
|
||||
|
||||
document.addEventListener('mousedown', listener);
|
||||
document.addEventListener('touchstart', listener);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', listener);
|
||||
document.removeEventListener('touchstart', listener);
|
||||
};
|
||||
}, [ref, handler]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue