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.

Faster way to show/hide components? Toggle component or toggle display?

See original GitHub issue
  • Toggle Component
render(){
  var Child = something? A : B;
  return (
    <Child />
  ) 
}
  • Toggle CSS Display is simple
className={this.props.shouldHide ? 'hidden' : ''} 

Issue Analytics

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

github_iconTop GitHub Comments

20reactions
sophiebitscommented, Aug 21, 2015

Writing {this.props.isHidden ? null : <SomeComponent/>} (or simpler, {!this.props.isHidden && <SomeComponent/>}) is easy and reduces the number of magic props you’d need to remember.

17reactions
MicronXDcommented, Jul 19, 2016

I also hate magic, but I think this could do so much for clean jsx markup that its magic-like behavior could be forgiven.

This muddies otherwise clean jsx markup: { !hideSomeComponent && <SomeComponent /> }

that could otherwise be handled like: <SomeComponent hidden={hideSomeComponent} />


It feels so gross doing this:

    <div>
        <img src="example.jpg" />
        { !hideSomeComponent && <SomeComponent>
            Example
        </SomeComponent>}
    <div>

instead of this:

    <div>
        <img src="example.jpg" />
        <SomeComponent hidden={hideSomeComponent}>
            Example
        </SomeComponent>
    <div>

I don’t think this would be the sort of magic where someone sits and wonders, “What does hidden do?”

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Ways To Show, Hide & Toggle an Element in React using ...
In this React JS tutorial, we take a look at five different ways to Show, Hide & Toggle in an Element in React...
Read more >
How to Use the Toggle Action to Show/Hide Elements
Bubble is a visual programming language that lets you build web applications without code. Using Bubble's visual editor, you can build a ...
Read more >
How To Toggle Between Hiding And Showing an Element
Toggle between hiding and showing an element with JavaScript. Toggle Hide and Show. Click the button! Toggle (Hide/Show) an Element. Step 1) Add...
Read more >
Toggle (Show/Hide) Element - JavaScript - CSS-Tricks
Inline usage: Click here to toggle visibility of element #foo This is foo. ... Hello, how can I use this show hide to...
Read more >
The Correct way to Toggle Display with JavaScript - W3Bits
Our previous solution depends on the inline display style of the element to perform display toggling. An easy way to create a better...
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