From 25a673b2c6715fde23fe79e08fee0113674e5c20 Mon Sep 17 00:00:00 2001 From: Jean Pan Date: Sat, 17 Dec 2022 22:34:51 +0900 Subject: [PATCH] fix: add clean up to avoid effect firing twice in strict mode (#1436) Co-authored-by: jeanpan --- src/hooks/useCombobox/index.js | 4 ++++ src/hooks/useMultipleSelection/index.js | 4 ++++ src/hooks/useSelect/index.js | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/hooks/useCombobox/index.js b/src/hooks/useCombobox/index.js index cff04761..e36d3f27 100644 --- a/src/hooks/useCombobox/index.js +++ b/src/hooks/useCombobox/index.js @@ -139,6 +139,10 @@ function useCombobox(userProps = {}) { // Make initial ref false. useEffect(() => { isInitialMountRef.current = false + + return () => { + isInitialMountRef.current = true + } }, []) // Reset itemRefs on close. useEffect(() => { diff --git a/src/hooks/useMultipleSelection/index.js b/src/hooks/useMultipleSelection/index.js index 74cda2a8..666638c0 100644 --- a/src/hooks/useMultipleSelection/index.js +++ b/src/hooks/useMultipleSelection/index.js @@ -99,6 +99,10 @@ function useMultipleSelection(userProps = {}) { // Make initial ref false. useEffect(() => { isInitialMountRef.current = false + + return () => { + isInitialMountRef.current = true + } }, []) // Event handler functions. diff --git a/src/hooks/useSelect/index.js b/src/hooks/useSelect/index.js index 9eb224a5..6243d607 100644 --- a/src/hooks/useSelect/index.js +++ b/src/hooks/useSelect/index.js @@ -159,6 +159,10 @@ function useSelect(userProps = {}) { // Make initial ref false. useEffect(() => { isInitialMountRef.current = false + + return () => { + isInitialMountRef.current = true + } }, []) // Reset itemRefs on close. useEffect(() => {