diff --git a/libs/shared/lib/components/tooltip/Tooltip.tsx b/libs/shared/lib/components/tooltip/Tooltip.tsx index a5afb88b23fa8f149f8d1c1bca51cd13b2dd63af..ac885ca6ecb82851ebfe9e8665a4130b98646c22 100644 --- a/libs/shared/lib/components/tooltip/Tooltip.tsx +++ b/libs/shared/lib/components/tooltip/Tooltip.tsx @@ -106,14 +106,13 @@ export const TooltipTrigger = React.forwardRef<HTMLElement, React.HTMLProps<HTML propRef, ) { const context = useTooltipContext(); - let childrenRef; - - if (children == null) { - const element = React.createElement('div'); - childrenRef = element.ref; - } else { - childrenRef = (children as React.ReactElement).ref; - } + const childrenRef = React.useMemo(() => { + if (children == null) { + return React.createElement('div').ref; + } else { + return (children as React.ReactElement).ref; + } + }, [children]); const ref = useMergeRefs([context.data.refs.setReference, propRef, childrenRef]);