question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I render react component within tooltip?

See original GitHub issue

Hi and thanks for sharing this library.

I’ve been testing a few and it is the only one that work.

One thing I need to do is to passe react-component within the tooltip, but the data-tip is the only prop I know that can be added in the tooltip and it expect a string.

Is it possible to render react-component within tooltips?

Thanks in advance

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
dmc1985commented, Jan 30, 2019

I was able to pass a React Component as the child of the tooltip by constructing a Tooltip component based on react-tooltip. Here is what I did:

<div>
    <ReactTooltip
        id={tooltipId}
        type={props.theme}
        effect='solid'
        place={props.place}
    >
        <p>{props.content}</p>
    </ReactTooltip>
    <div data-tip data-for={tooltipId}>
        {props.children}
    </div>
</div>

The key is to construct a unique Id for each tooltip that will appear on the same page to prevent collisions. I did that by using the props I pass to the Tooltip component. So at the top of the Tooltip component, I put: const tooltipId = ${props.content}+${props.title}+${props.theme}+${props.place} (please note that I put backticks around the templated string - hard to format this with markdown)

This allows me to render react components within my Tooltip component like so:

<Tooltip content={props.title} theme="dark" place="bottom">
                <h4>{props.title}</h4>
</Tooltip>

I hope this helps you!

3reactions
dmc1985commented, Feb 6, 2020

Hi @dmc1985, any progress in your PR?

Thanks for following up on this and my apologies for the delay. I still would like to do a PR to update the doc with the code snippet, and my goal is to do it over the weekend.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I render react component within tooltip? #467 - GitHub
@kopax Yes I found that it does work with a react component. You could create a simple functional component like so: function Tooltip(props)...
Read more >
React Tooltip using Components - Stack Overflow
1 Answer 1 · You should use the data-html={true} prop to let the react-tooltip know that the value passed to data-tip is actually...
Read more >
How To Make an Extremely Reusable Tooltip Component ...
It takes everything inside a <Tooltip> component and moves it inside a div with Tooltip-Wrapper class by using props.children; It controls what ...
Read more >
Building a Tooltip Component with React - Medium
If the button is all the way at the bottom, then render the tooltip above it. First things first, let's create the DOM...
Read more >
4 Ways to Show Tooltips in React with react-tooltip, Material UI ...
We use ReactTooltip to render the content of the tooltip. We specify the id property for the tooltip and a content. The place...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found