React 多个className的写法

385 阅读1分钟

方法一: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(' ')}