classnames库的简单使用

647 阅读1分钟

import classnames from 'classnames';

constructor (props) {    super(props);    this.state = {        isLoading: true,        contentType: 'text',    }}

render () {
    <div className={classnames(        'content',        {            'is-loading': this.state.isLoading,            [`content-type-${this.state.contentType}`]: true,        },        null,        undefined,        false,        0,        {            'isNull': null,            'isUndefined': undefined,        }    )}>}

classnames库就是为了很方便地给元素添加类名,可以传入任意参数,根据参数来判断是否该添加什么样的样式

结果: