Skip to content

Commit

Permalink
fix: [useClickOutside] fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
akai committed May 19, 2021
1 parent 290b90d commit 0ca4d86
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/components/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Navbar, NavbarProps } from '../Navbar';
import { MessageContainer, MessageContainerProps } from '../MessageContainer';
import { QuickReplies, QuickReplyItemProps } from '../QuickReplies';
import { Composer as DComposer, ComposerProps } from '../Composer';
import { MessageProps } from '../Message/Message';

export type ChatProps = ComposerProps &
MessageContainerProps & {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const Popover: React.FC<PopoverProps> = (props) => {
const [style, setStyle] = useState({});

const updatePos = useCallback(() => {
if (!wrapper.current) return;

const targetRect = target.getBoundingClientRect();
const rect = wrapper.current.getBoundingClientRect();

Expand Down
10 changes: 4 additions & 6 deletions src/hooks/useClickOutside.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { useEffect, useRef } from 'react';

type EventType = MouseEvent | TouchEvent;

export default function useClickOutside(
handler: (event: EventType) => void,
export default function useClickOutside<T extends HTMLElement = any>(
handler: (event: any) => void,
eventName: string = 'click',
) {
const ref = useRef<HTMLElement>(null);
const ref = useRef<T>();

useEffect(() => {
const listener = (e: any) => {
Expand All @@ -25,7 +23,7 @@ export default function useClickOutside(
return () => {
document.removeEventListener(eventName, listener);
};
}, [handler, eventName]);
}, [eventName, handler]);

return ref;
}

0 comments on commit 0ca4d86

Please sign in to comment.