react conditional css code example
Example 1: react conditional classname
<div className={`banner ${active ? "active" : ""}`}>{children}</div>
Example 2: conditional style react
class App extends Component {
constructor() {
super()
this.state = { isRed: true }
}
render() {
const isRed = this.state.isRed
return <p style={{ color: isRed ? 'red' : 'blue' }}>Example Text</p>
}
}
Example 3: react conditional class
<div className={"btn-group pull-right " + (this.props.showBulkActions ? 'show' : 'hidden')}>
Example 4: conditional classname prop react
<span className={todo.completed ? "true" : ""}>
Example 5: conditional style react
<ImageBackground source={Images.bg} style={ (navHeight==0) ? styles.bg1 : styles.bg2}>