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.

Is it possible to conditionally render only the component?

See original GitHub issue

I’m using tippyjs/react. Sometimes I only wish to render my component, and not the tooltip as well.

My solution seems like a bit of an anti-pattern:

{window.myVariable && <SomeComponent/>}
{!window.myVariable &&
<Tippy content={<div>hi</div>}>
    <SomeComponent/>
</Tippy>
}

I’m looking for something like an attribute I can attach to Tippy e.g.

<Tippy showTip={!window.myVariable} content={<div>hi</div>}>
    <SomeComponent/>
</Tippy>

Thanks

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
atomikscommented, Nov 12, 2018

Yeah there’s a few ways:

  1. Conditional rendering as you’re doing currently
{window.myVariable ? (
  <SomeComponent />
) : (
  <Tippy content="Tooltip">
    <SomeComponent />
  </Tippy>
)}
  1. Return false in onShow if you don’t want to show it
const onShow = () => !window.myVariable

<Tippy onShow={onShow}>
  <SomeComponent />
</Tippy>
  1. Call .enable() / .disable() imperatively on the instance

I think there should be React-specific props for this however: like isEnabled which is part of the state object. Maybe isVisible, too

2reactions
atomikscommented, May 27, 2019

@tippy.js/react@2 is dependent on tippy.js@4 (v4 major) Also, there were breaking changes in v2 obviously, you can read the release notes to find out

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 Ways to Implement Conditional Rendering in React ...
This article covers seven different ways to implement conditional rendering in React applications with practical examples and performance ...
Read more >
Six methods to achieve conditional rendering in React - Flexiple
Conditional rendering in React works the same way conditions work in JavaScript. Use JavaScript operators like if, and let React update the UI ......
Read more >
React conditional rendering: 9 methods with examples
In React, conditional rendering refers to the process of delivering elements and components based on certain conditions. There's more than one ...
Read more >
is there anyway to conditionally render a React component ...
Yes, components may be rendered conditionally. Inside your render() {} method you can do something like... render() { if (condition1) ...
Read more >
How to Show Components Conditionally in React | Pluralsight
Introduction · Option 1 - If Component · Option 2 - IIFE · Option 3 - Variable · Option 4 - Render Function...
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