I have a React menu item that should surface a subcomponent on hover. When that subcomponent info-icon
is hovered, a tooltip should pop open. which looks like this:
Here is the component:
const TestFunc = (props) => {
const { icon, label, data } = props;
const [hovering, setState] = useState(false);
return (
<div className="menu-item" onMouseOver={() => setState(true)} onMouseOut={() => setState(false)}>
<div className="menu-item-element">
<div className="sub-menu-item-element">{icon}</div>
<div className="sub-menu-item-element">{label}</div>
</div>
{hovering ?
<Tooltip
id="base"
align="top"
content={data.tooltipContent}
variant="learnMore"
className="menu-item-element"
position="overflowBoundaryElement"
/>
: null
}
</div>
);
But when I hover over the info icon, this triggers the mouseOut
function then the icon disappears, which then triggers the mouseOver
function and it just loops like that with the info icon flashing over and over.
How do I fix this?