Skip to content Skip to sidebar Skip to footer

Adding Dynamic Class Name To List Of Hard Coded Classes In React

I have an element with a list of classes e.g.
Content
And I want to add this react variable to the list of classes: {this.stat

Solution 1:

you can do the following using template strings:

<div className={`${this.state.active ? 'is-active': ''} class1 class2 class3`}>Content</div>

Solution 2:

this will work but it's not very good coding

you can do this like this

<div class={{this.state.active ? " class1 class2 class3 is-active": "class1 class2 class3"}}>Content</div>

Post a Comment for "Adding Dynamic Class Name To List Of Hard Coded Classes In React"