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:
- Created 8 years ago
- Comments:17 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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:
instead of this:
I don’t think this would be the sort of magic where someone sits and wonders, “What does hidden do?”