React does not support the visibility attribute for elements.
So if I want to show or hide an element on the page, but still have it take up space when hidden so the layout doesn't shift, how do I do something like this?
<i className="fa fa-trash" visibility={this.state.showButton ? "visible": "hidden"} />
Using visibility: hidden hides an element from the browser; however, that hidden element still lives in the source code. Basically, visibility: hidden makes the element invisible to the browser, but it still remains in place and takes up the same space had you not hidden it.
Sensor component for React that notifies you when it goes in or out of the window viewport.
You can use CSS for this.
<i className="fa fa-trash" style={{visibility: this.state.showButton ? 'visible' : 'hidden' }} />
Learn more about inline styles in React
You can use a CSS class for that and dynamically modify your className. For example:
<i className={this.state.showButton ? "fa fa-trash" : "fa fa-trash hidden"} />
This is a css-attribute so you can use inline-styles:
...
var visibilityState = this.state.showButton ? "visible" : "hidden";
return (
<i className="fa fa-trash" style={{visibility: visibilityState}}/>
);
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With