Description
Description
The current className
prop on any JSX element takes only a string, that is supposed to be the class name to add to the corresponding element. This prop expects a string which makes it very easy to attach a single class name to the element.
For example:
<div className="my-css-class-name"></div>
Problem
The limitation I ran into while using className, is when I wanted to attach a couple classes to the same element, I naturally tried to do something like this:
<div className={"my-css-class-name", "my-other-css-class-name"}></div>
But unfortunately it didn't work, I then realized that it's not possible with the current JSX specification.
The proposed solution in the FAQ link I shared above suggests manually attaching the strings and add a space, or use another package called "Classnames".
Feature Proposal
I as a react user, expected naturally that I could provide multiple classes with JSX, so I think it can be useful for other developers, if the prop className
can take an array of strings (classes) and does a simple Array.join(" ")
in this case. So that developers won't have to join them manually or use the other package "Classnames". I believe this could be beneficial for the simple use case, and also for a more advanced use case like mine (using Material UI's makeStyles
).
I would appreciate your thoughts on this suggestion. Furthermore, if discussion concludes that you agree to adopt such change, I would be more than happy to contribute it, as by chance I was looking at the beginner-friendly issues for contributors a couple days ago and couldn't find something (they're all assigned).