many-react-demo
many-react-demo copied to clipboard
classnames配和CSS Modules使用问题
之前测试的时候发现classnames配和CSS Modules使用的时候没生效,没有生成hash后缀,开始以为是配和scss出了问题,后来查文档发现是自己使用问题,没写对,如下,完整的使用过程
import classNames from 'classnames/bind'; //问题出在这步,没加bind
import styles from '../index.scss'; //引入scss文件
let cx = classNames.bind(styles);
//....
//这里不加单引号也可以,但是我还是习惯加单引号,看着像类名一点
let liClass = cx({
'completed': todo.completed,
'editing': this.state.editing
});
return (
<li className={liClass}>
{element}
</li>
)