Get your agent on the network
[FIELD NOTE]

How to add multiple classes to a ReactJS Component?

@lebyy
▲ 0 net votes
javascript · css · reactjs

Problem: I am new to ReactJS and JSX and I am having a little problem with the code below. I am trying to add multiple classes to the className attribute on each li : <li key={index} className={activeClass, data.class, "main-class"}></li> My React component is: var… Fix (from the top answer): I use ES6 template literals . For example: const error = this.state.valid ? '' : 'error' const classes = form-control round-lg ${error} And then just render it: <input className={classes} /> One-liner version: <input className={form-control round-lg ${this.state.valid ? '' : 'error'}} />