Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit 2ef5b0f

Browse files
tjrdnjs1534po4tionraon0211
authored
fix(@toss/react): add useOutsideClickEffect dependency for preventing keep add and remove eventlistener (#453)
* fix: add callback dependency on useOutsideClickEffect using preservedCallback * fix: delete touchstart event from `useOutsideClickEffect` * Revert "fix: delete touchstart event from `useOutsideClickEffect`" This reverts commit c1b09c9. * fix(@toss/validators): Increase the accuracy of verification for isBirthDate6 (#420) * fix(@toss/validators): Increase the accuracy of verification * test(@toss/validators): add test case * fix: catch 2000y bug * refactor: change from magic number to constant variable * test: split test case * refactor: change constant variable name * refactor(@toss/validators): use proper library(date-fns) * chore(release): Publish libraries [skip ci] - @toss/rollup-config@0.2.0 - docs@1.0.19 - @toss/assert@1.2.0 - @toss/crypto@1.2.0 - @toss/date@1.2.0 - @toss/hangul@1.7.0 - @toss/ky@1.2.0 - @toss/sentry@1.1.0 - @toss/storage@1.4.0 - @toss/utility-types@1.2.0 - @toss/utils@1.5.0 - @toss/validators@1.3.0 - @toss/a11y@1.3.0 - @toss/async-boundary@1.5.0 - @toss/async-stylesheet@1.2.0 - @toss/emotion-utils@1.2.0 - @toss/error-boundary@1.5.0 - @toss/framer-motion@1.2.0 - @toss/impression-area@1.4.0 - @toss/lottie@1.3.0 - @toss/react-query@1.3.0 - @toss/react@1.7.0 - @toss/recoil@1.2.0 - @toss/redirect@1.3.0 - @toss/scroll-animation@1.3.0 - @toss/use-funnel@1.4.0 - @toss/use-loading@1.2.0 - @toss/use-overlay@1.4.0 - @toss/use-query-param@1.3.0 * Revert "chore(release): Publish libraries [skip ci]" This reverts commit c325c90. * Revert "fix(@toss/validators): Increase the accuracy of verification for isBirthDate6 (#420)" This reverts commit 2565f17. * Apply suggestions from code review --------- Co-authored-by: Dongkyu Kim <po4tion0429@gmail.com> Co-authored-by: raon0211 <raon0211@toss.im> Co-authored-by: Sojin Park <raon0211@gmail.com>
1 parent 2df8203 commit 2ef5b0f

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

packages/react/react/src/hooks/useOutsideClickEffect.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import { isNotNil } from '@toss/utils';
2-
import { useCallback, useEffect, useRef } from 'react';
2+
import { useEffect, useRef } from 'react';
3+
import { usePreservedCallback } from './usePreservedCallback';
34

45
type OneOrMore<T> = T | T[];
56

67
/** @tossdocs-ignore */
78
export function useOutsideClickEffect(container: OneOrMore<HTMLElement | null>, callback: () => void) {
89
const containers = useRef<HTMLElement[]>([]);
910

10-
const handleDocumentClick = useCallback(
11-
({ target }: MouseEvent | TouchEvent) => {
12-
if (target === null) {
13-
return;
14-
}
1511

16-
if (containers.current.length === 0) {
17-
return;
18-
}
12+
const handleDocumentClick = usePreservedCallback(({ target }: MouseEvent | TouchEvent) => {
13+
if (target === null) {
14+
return;
15+
}
1916

20-
if (containers.current.some(x => x.contains(target as Node))) {
21-
return;
22-
}
17+
if (containers.current.length === 0) {
18+
return;
19+
}
2320

24-
callback();
25-
},
26-
[callback]
27-
);
21+
if (containers.current.some(x => x.contains(target as Node))) {
22+
return;
23+
}
24+
25+
callback();
26+
});
2827

2928
useEffect(() => {
3029
containers.current = [container].flat(1).filter(isNotNil);

0 commit comments

Comments
 (0)