Render
Using the ReactTooltip render prop to render dynamic content based on the active anchor element.
Basic usage
The render prop can be used to render the tooltip content dynamically based on the currently active anchor element.
The function signature is as follows:
(render: { content: ReactNode | null; activeAnchor: HTMLElement | null }) => ReactNode
contentis the tooltip content (from thecontentprop or thedata-tooltip-contentattribute on the anchor element)activeAnchoris a ref to the anchor element currently active (ornullif no element is active)
import { Tooltip } from 'react-tooltip';
<a
data-tooltip-id="my-tooltip"
data-tooltip-content="1"
data-some-relevant-attr="wow"
>
◕‿‿◕
</a>
<a
data-tooltip-id="my-tooltip"
data-tooltip-content="2"
data-some-relevant-attr="so relevant"
>
◕‿‿◕
</a>
<a
data-tooltip-id="my-tooltip"
data-tooltip-content="3"
data-some-relevant-attr="much important"
>
◕‿‿◕
</a>
<Tooltip
id="my-tooltip"
render={({ content, activeAnchor }) => (
<span>
The element #{content} is currently active.
<br/>
Relevant attribute: {activeAnchor?.getAttribute('data-some-relevant-attr') || 'not set'}
</span>
)}
/>
◕‿‿◕
◕‿‿◕
◕‿‿◕
