Skip to content

Commit

Permalink
fix: add clean up to avoid effect firing twice in strict mode (#1436)
Browse files Browse the repository at this point in the history
Co-authored-by: jeanpan <[email protected]>
  • Loading branch information
jeanpan and jeanpan authored Dec 17, 2022
1 parent 795a8d1 commit 25a673b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useCombobox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ function useCombobox(userProps = {}) {
// Make initial ref false.
useEffect(() => {
isInitialMountRef.current = false

return () => {
isInitialMountRef.current = true
}
}, [])
// Reset itemRefs on close.
useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useMultipleSelection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ function useMultipleSelection(userProps = {}) {
// Make initial ref false.
useEffect(() => {
isInitialMountRef.current = false

return () => {
isInitialMountRef.current = true
}
}, [])

// Event handler functions.
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ function useSelect(userProps = {}) {
// Make initial ref false.
useEffect(() => {
isInitialMountRef.current = false

return () => {
isInitialMountRef.current = true
}
}, [])
// Reset itemRefs on close.
useEffect(() => {
Expand Down

0 comments on commit 25a673b

Please sign in to comment.