How can I add multiple className's to react component?

后端 未结 4 1492
时光说笑
时光说笑 2021-02-07 03:44

I need to add one className to a component which is being passed down from the parent, and another className that doesn\'t have anything to do with its parent, but with the comp

相关标签:
4条回答
  • 2021-02-07 04:09
    <div className={(classes.shiny, classes.round)}>
        i'm shiny and round.
    </div>
    

    This works with React + Material-UI makeStyles.

    0 讨论(0)
  • 2021-02-07 04:18

    <div className={this.state.className && this.props.content.divClassName></div>

    0 讨论(0)
  • 2021-02-07 04:27
    <div className={`${this.state.className} ${this.props.content.divClassName}`}>
    

    Or if you can't use template strings:

    <div className={[this.state.className, this.props.content.divClassName].join(" ")}>
    
    0 讨论(0)
  • 2021-02-07 04:29

    Combo of string and props class is here

    className={`${props.myClass} MyStringClass`}
    
    0 讨论(0)
提交回复
热议问题