Reputation: 3567
I'm trying to set the an elements attributes that is from a state
this.state = {
label : 'Hello',
columns: [4, 8],
test: 'has-success'
}
I was trying to set the col-md value like so:
<label className="control-label text-sm-right col-sm-{this.state.columns[0]}">
but that didnt work. So I wanted to see what that values is if I used the console.log()
console.log('control-label text-sm-right col-sm-{this.state.columns[0]}');
and the output shows that it didnt change the value to col-sm-4:
but when I use it this way it works:
<span className="input-group-addon">{this.state.columns[0]}</span>
Upvotes: 0
Views: 84
Reputation: 181
If you are using ES6, you can use template string literals.
<label className={`control-label text-sm-right col-sm-${this.state.columns[0]}`}>
Upvotes: 0
Reputation: 33628
Append a string to the variable. Something like this instead
className={"control-label text-sm-right col-sm-"+this.state.columns[0]}
Upvotes: 1