The proposed solutions are actually "ng-if" equivalents of React. If you use ng-if and the status is false, the component will not display in the DOM. If you use ng-show / hide, it will appear in the DOM, but it will be hidden in the browser.
In many cases, the {myVar && <div />} solution will work as expected, but there may be times when it is not an ideal solution. Because it will load / unload the component, not show / hide. For instance; if you have a tab container and you use it to show / hide the contents of the tab; depending on the selected tab, every time you load / unload other content. This can be a problem if you use reduction molds or similar approaches. Here you need some kind of ng-show, not ng-if.
Since React does not have attribute directives, you need to either write a HOC or a shell component (element directive) that handles this. Or just add a dynamic inline style like this:
<div style={{ display: myVar ? 'block' : 'none' }}> <h1>Welcome</h1> <p>Welcome to my home.</p> </div>
source share