DEV Community

Discussion on: You do not need to use the classnames package

Collapse
 
tomekbuszewski profile image
Tomek Buszewski

I remember ditching classnames long ago. At some point we've decided that vendor for joining strings is an overkill. I think we've used something like this (pseudocode):

const cls = (input: string|boolean[]): string => input.filter((cond: string | boolean) => typeof cond === "string").join(", ");

<div className={cls(["one", isTrue ? "two" : "three", isAnything && "four"]) />
Enter fullscreen mode Exit fullscreen mode

And it worked perfectly. You could drop the filter element, but then you'll get false as one of the classes from time to time.