Skip to content

Commit a64221b

Browse files
fix: rearrange some useEffect deps
1 parent 877fb33 commit a64221b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Diff for: src/components/Tooltip/Tooltip.tsx

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { useEffect, useState, useRef } from 'react'
1+
import React, { useEffect, useState, useRef, useCallback } from 'react'
2+
import { autoUpdate } from '@floating-ui/dom'
23
import classNames from 'classnames'
34
import debounce from 'utils/debounce'
45
import { useTooltip } from 'components/TooltipProvider'
56
import useIsomorphicLayoutEffect from 'utils/use-isomorphic-layout-effect'
6-
import { autoUpdate } from '@floating-ui/dom'
77
import { getScrollParent } from 'utils/get-scroll-parent'
88
import { computeTooltipPosition } from 'utils/compute-positions'
99
import coreStyles from './core-styles.module.css'
@@ -291,7 +291,7 @@ const Tooltip = ({
291291
// mouse enter and focus events being triggered toggether
292292
const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true)
293293
const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true)
294-
const updateTooltipPosition = () => {
294+
const updateTooltipPosition = useCallback(() => {
295295
if (position) {
296296
// if `position` is set, override regular and `float` positioning
297297
handleTooltipPosition(position)
@@ -335,7 +335,17 @@ const Tooltip = ({
335335
}
336336
setActualPlacement(computedStylesData.place as PlacesType)
337337
})
338-
}
338+
}, [
339+
show,
340+
activeAnchor,
341+
content,
342+
externalStyles,
343+
place,
344+
offset,
345+
positionStrategy,
346+
position,
347+
float,
348+
])
339349

340350
useEffect(() => {
341351
const elementRefs = new Set(anchorRefs)
@@ -458,7 +468,15 @@ const Tooltip = ({
458468
* rendered is also a dependency to ensure anchor observers are re-registered
459469
* since `tooltipRef` becomes stale after removing/adding the tooltip to the DOM
460470
*/
461-
}, [rendered, anchorRefs, anchorsBySelect, closeOnEsc, events])
471+
}, [
472+
activeAnchor,
473+
updateTooltipPosition,
474+
rendered,
475+
anchorRefs,
476+
anchorsBySelect,
477+
closeOnEsc,
478+
events,
479+
])
462480

463481
useEffect(() => {
464482
let selector = anchorSelect ?? ''
@@ -538,7 +556,7 @@ const Tooltip = ({
538556

539557
useEffect(() => {
540558
updateTooltipPosition()
541-
}, [show, activeAnchor, content, externalStyles, place, offset, positionStrategy, position])
559+
}, [updateTooltipPosition])
542560

543561
useEffect(() => {
544562
if (!contentWrapperRef?.current) {

0 commit comments

Comments
 (0)