From 04d0b850a541ca938e5994f916293d4cca133c86 Mon Sep 17 00:00:00 2001 From: jeanpan Date: Wed, 30 Nov 2022 14:48:39 +0900 Subject: [PATCH] fix: add clean up to avoid effect firing twice in strict mode --- 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 19f6972c..146e993d 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(() => {