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.

ReactTooltip getContent callback is called more than once for a ReactTooltip component with effect="solid"

See original GitHub issue

After rendering the following component:

export default class TestComponent extends React.PureComponent {

    constructor(props) {
        super(props)

        this.tooltipId = elementUniqueId() // Creates a unique ID. I checked the DOM and this ID is always unique.
    }

    render() {
        const tooltip = 'TEST!!!'

        console.warn('render()')

        return (
            <div>
                <span data-tip={tooltip}
                    data-for={this.tooltipId}>
                    HOVER ME!
                </span>
                <ReactTooltip id={this.tooltipId}
                    effect="solid"
                    place="right"
                    getContent={function() {
                        console.warn('getContent()')
            
                        return (
                            <div>{tooltip}</div>
                        )
                    }} />
            </div>
        )
    }

}

I see the following in the console:

> console.warn('render()') // OK
> console.warn('getContent()') // OK

At this point, the tooltip hasn’t been shown yet. From this point on, each time I hover the span element to trigger the tooltip, I can see in the console that getContent() is always called 3 times when the mouse hovers the element showing the tooltip and 2 times when the mouse leaves the element:

// I hover the span element (the tooltip shows):
> console.warn('getContent()') // OK
> console.warn('getContent()') // NOT OK. Why is the callback called again?
> console.warn('getContent()') // NOT OK. And again?

// I move the mouse out of the span element (the tooltip hides):
> console.warn('getContent()') // NOT OK. Why does it call getContent in the first place if the tooltip is hiding?
> console.warn('getContent()') // NOT OK. Why does it call getContent in the first place if the tooltip is hiding?

Also, I noticed that getContent is called several times if I resize the browser’s page even if the tooltip is not showing.

Am I missing something or this is the actual behaviour and if so why does it work like this?

Anyway, I would like to that you for this component and for your attention.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

1reaction
kurochkinSergeicommented, Jun 25, 2021

I had a grid of elements with tooltips on each item debouncing getContent and keeping only trailing one did the job:

import debounce from 'lodash/debounce';

const MyComponent = () => {
  const debouncedGetContent = debounce(() => {....}, 500, { leading: false, trailing: true });
  ...
  return (
  <>
    <ReactTooltip
      effect="solid"
       multiline
       delayShow={1000}
       delayHide={0}
       getContent={debouncedGetContent}
    />
  </>
  )
}
1reaction
warrenc5commented, Feb 16, 2021

I was calling the memoize function 200 times _M_renderCrewLocation = memoize(this.renderCrewLocation)

I moved the memoize into the constructor

return (
                    <span style={{paddingLeft: "3px"}}>
                        <a data-tip data-for={keyId} style={{color: 'red'}}>L</a>
                       
                       {
                        <ReactTooltip
                            id={keyId}
                            place="right"
                            type="info"
                            effect="solid"
                            delayUpdate={100}
                            border={false}
                            className="customTheme"
                            getContent={keyId => trip != null ? this._M_renderCrewLocation(keyId,trip) : ""}
                            /> 
                            //https://github.com/wwayne/react-tooltip/issues/506
                        }

                    </span>
                    )
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactTooltip getContent callback is called more than once for ...
After rendering the following component: export default class TestComponent extends React.PureComponent { constructor(props) { super(props) ...
Read more >
react-tooltip - Bountysource
ReactTooltip getContent callback is called more than once for a ReactTooltip component with effect="solid" $ 0 ... Created 3 years ago in wwayne/react-tooltip ......
Read more >
React-tooltip rendering two times - Stack Overflow
Then I have this other component where I pass some props to the Tooltip component and I just want this only component to...
Read more >
React-tooltip vs Material UI Tooltip Comparison and Examples
Then we dive into how Material UI uses Popper.js, and how we can build an interactive Tooltip that stays open while interacting with...
Read more >
React tooltip Component - Morioh
The component was designed to set <ReactTooltip /> once and then use tooltip everywhere ... If your modal's z-index happens to be higher...
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