React Answers

How to add multiple classes to a ReactJS Component?

Spread the love

To add multiple classes to a ReactJS Component, we can set the className propt to a string with the classes separated by spaces.

For instance, we write

<li className={[activeClass, data.klass, "main-class"].join(" ")}>...</li>;

to join the activeClass, data.klass and 'main-class strings together with join.

Then all the classes are applied to the li element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *