方法一:ES6 模板字符串 ``
className={title ${index === this.state.active ? 'active' : ''}}
import styles from './index.module.scss';
interface PropsType{
className: string;
}
const app: React.FC<PropsType> = () => {
return (
<>
<div className = {`${styles.link} ${className}`}></div>
</>
)
}
方法二:join("")
className={["title", index === this.state.active?"active":null].join(' ')}