From 16d345ec1aaf03d0dccfc94b57c951345e87b74e Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Mon, 5 Sep 2022 16:58:38 +0200 Subject: [PATCH] Simplify code --- packages/components/src/tooltip/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/components/src/tooltip/index.js b/packages/components/src/tooltip/index.js index 5e152b874b928..c2d438f4ad41c 100644 --- a/packages/components/src/tooltip/index.js +++ b/packages/components/src/tooltip/index.js @@ -9,7 +9,6 @@ import { concatChildren, useEffect, useState, - useCallback, } from '@wordpress/element'; import { useDebounce, useMergeRefs } from '@wordpress/compose'; @@ -131,11 +130,11 @@ function Tooltip( props ) { // Create a reference to the Tooltip's child, to be passed to the Popover // so that the Tooltip can be correctly positioned. Also, merge with the // existing ref for the first child, so that its ref is preserved. - const childRef = useCallback( ( node ) => { - setPopoverAnchor( node ?? undefined ); - }, [] ); const existingChildRef = Children.toArray( children )[ 0 ]?.ref; - const mergedChildRefs = useMergeRefs( [ childRef, existingChildRef ] ); + const mergedChildRefs = useMergeRefs( [ + setPopoverAnchor, + existingChildRef, + ] ); const createMouseDown = ( event ) => { // In firefox, the mouse down event is also fired when the select @@ -258,7 +257,8 @@ function Tooltip( props ) { : getRegularElement; const popoverData = { - anchor: popoverAnchor, + // `anchor` should never be `null` + anchor: popoverAnchor ?? undefined, isOver, offset: 4, position,