Skip to content

Commit

Permalink
Fix: build error
Browse files Browse the repository at this point in the history
  • Loading branch information
MEGUMMY1 committed Dec 22, 2024
1 parent 615e3d6 commit 5db17ff
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/hooks/useClickOutside.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { useEffect, useRef } from 'react';
import { useEffect, useRef, useCallback } from "react";

export default function useClickOutside<T extends HTMLElement>(
callback: () => void
) {
export default function useClickOutside<T extends HTMLElement>(callback: () => void) {
const ref = useRef<T>(null);

const memoizedCallback = useCallback(callback, [callback]);

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (ref.current && !ref.current.contains(event.target as Node)) {
callback();
memoizedCallback();
}
};

document.addEventListener('mousedown', handleClickOutside);
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);
}, [memoizedCallback]);

return ref;
}

0 comments on commit 5db17ff

Please sign in to comment.