Skip to content

Commit

Permalink
Filter out null refs
Browse files Browse the repository at this point in the history
  • Loading branch information
philipprus committed Sep 2, 2024
1 parent aecb649 commit 5699a2f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/useClickAway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const useClickAway = <E extends Event = Event>(
useEffect(() => {
const handler = (event) => {
const refArray = Array.isArray(refs) ? refs : [refs];
if (refArray.every(ref => ref.current && !ref.current.contains(event.target))) {
const existingRefs = refArray.filter((ref) => Boolean(ref?.current)); // Filter out null refs
if (existingRefs.every(ref => ref.current && !ref.current.contains(event.target))) {
savedCallback.current(event);
}
};
Expand Down

0 comments on commit 5699a2f

Please sign in to comment.