-
-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] useOnClickOutside doesn't allow null ref #663
Comments
Yeah, just hit this while updating dependencies. It started erroring before I updated from 2.9.1 to 3.1.0, though; so I don't think this is a mere regression. Regardless, what's the intended fix here? Kinda frustrated. |
Before a fix is available you can override the types like so: useOnClickOutside<HTMLUListElement>(ref as React.RefObject<HTMLUListElement>, () => setIsOpen(false)); although, I am not endorsing it. |
Im hitting the same error with useResizeObserver . Is this potentially related? I hit this error when updating to react v19. |
import 'usehooks-ts'
// React 19 issue: https://github.com/juliencrn/usehooks-ts/issues/663
declare module 'usehooks-ts' {
declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(
ref: RefObject<T | null | undefined> | RefObject<T | null | undefined>[],
handler: (event: MouseEvent | TouchEvent | FocusEvent) => void,
eventType?: EventType,
eventListenerOptions?: AddEventListenerOptions
): void
declare function useHover<T extends HTMLElement = HTMLElement>(elementRef: RefObject<T | null | undefined>): boolean;
} |
Describe the bug
The sample code in https://usehooks-ts.com/react-hook/use-on-click-outside#usage throws a TypeError:
To Reproduce
Expected behavior
Should accept null
Additional context
No response
The text was updated successfully, but these errors were encountered: