react 设置多个className
方法一:ES6 模板字符串 ``
className={`title ${index === this.state.active ? 'active' : ''}`}
方法二:join("")
className={["title", index === this.state.active?"active":null].join(' ')}
方法三:classnames(需要下载classnames)
const classNames = require('classnames'); const Button = React.createClass({ // ... render () { const btnClass = classNames({ btn: true, 'btn-pressed': this.state.isPressed, 'btn-over': !this.state.isPressed && this.state.isHovered }); return <button className={btnClass}>{this.props.label}</button>; } });