How to add multiple classes to a ReactJS Component?

后端 未结 29 2199
执念已碎
执念已碎 2020-11-27 09:16

I am new to ReactJS and JSX and I am having a little problem with the code below.

I am trying to add multiple classes to the className attribute on eac

29条回答
  •  眼角桃花
    2020-11-27 09:42

    I bind classNames to the css module imported to into the component.

    import classNames from 'classnames'; 
    import * as styles from './[STYLES PATH];
    const cx = classNames.bind(styles); 
    

    classnames gives the ability to declare className for a React element in a declarative way.

    ex:

    Lorem
    Lorem
    // global css declared without css modules
    Lorem
    // conditionally assign classes
    Lorem
    //combine multiple classes

提交回复
热议问题