Initial commit

This commit is contained in:
Igor Martyniuk
2026-06-25 15:53:49 +03:00
commit 1bb0b7e68a
1517 changed files with 218469 additions and 0 deletions
@@ -0,0 +1,35 @@
# useOutsideClick
Detects clicks and touches outside a referenced element and calls a callback.
## Signature
```ts
function useOutsideClick(callback: () => void): React.RefObject<HTMLDivElement>;
```
| Parameter | Type | Description |
| ---------- | ------------ | ------------------------------------------------ |
| `callback` | `() => void` | Called when a click/touch occurs outside the ref |
Returns a `ref` to attach to the element you want to monitor.
## Usage
```tsx
function Dropdown({ onClose }: { onClose: () => void }) {
const ref = useOutsideClick(onClose);
return (
<div ref={ref}>
<p>Dropdown content</p>
</div>
);
}
```
## Notes
- Listens to both `mouseup` and `touchend` to cover desktop and mobile.
- If `callback` changes on every render, wrap it in `useCallback` to avoid resetting listeners unnecessarily.
- Client-only (`'use client'`).