I have an example:
var myClass = '';
if (this.state.foo) myClass = 'active';
return (
<div className={myClass}></div>
)
Or inside return:
return (
<div className={this.state.foo ? 'active' : '' }></div>
)
If this.state.foo- falsein the browser, my code will look:
<div class></div>
Is it possible to add an attribute classif it is empty?
source
share