How to add multiple classes in Material UI using the classes props

后端 未结 11 2026
花落未央
花落未央 2020-12-23 15:39

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

Here is the classes variable:

const styles = theme          


        
11条回答
  •  渐次进展
    2020-12-23 16:17

    To have multiple classes applied to a component, wrap the classes you would like to apply within classNames.

    For example, in your situation, your code should look like this,

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

    Make sure that you import classNames!!!

    Have a look at material ui documentation where they use multiple classes in one component to create a customized button

提交回复
热议问题