如何使用类道具在Material UI中添加多个类 [英] How to add multiple classes in Material UI using the classes props

查看:124
本文介绍了如何使用类道具在Material UI中添加多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用css-in-js方法向React组件添加类,如何添加多个组件?

Using the css-in-js method to add classes to a react component, how do I add multiple components?

这是class变量:

const styles = theme => ({
 container: {
  display: 'flex',
  flexWrap: 'wrap'
},
 spacious: {
  padding: 10
},
});

这是我的用法:

    return (
     <div className={ this.props.classes.container }>

以上方法有效,但是有没有一种方法可以添加两个类,而无需使用classNames npm包?像这样:

The above works, but is there a way to add both classes, without using the classNames npm package? Something like:

     <div className={ this.props.classes.container + this.props.classes.spacious}>

推荐答案

您可以使用字符串插值:

you can use string interpolation:

<div className={`${this.props.classes.container} ${this.props.classes.spacious}`}>

这篇关于如何使用类道具在Material UI中添加多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆