How to add multiple classes to a ReactJS Component?

后端 未结 29 2207
执念已碎
执念已碎 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条回答
  •  萌比男神i
    2020-11-27 09:29

    I use classnames when there is a fair amount of logic required for deciding the classes to (not) use. An overly simple example:

    ...
        var liClasses = classNames({
          'main-class': true,
          'activeClass': self.state.focused === index
        });
    
        return (
  • {data.name}
  • ); ...

    That said, if you don't want to include a dependency then there are better answers below.

提交回复
热议问题