DEV Community

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

Collapse
 
lesbaa profile image
Les • Edited

Agreed, I think classNames is a bit of overkill for what is essentially concatenation of strings. However template literals can get hectic and hard to reason about very quickly. What I normally do is:

const componentClassName = [
  'some-base-class',
  someBooleanCondition && 'a-class-in-here',
  someOtherBoolean && 'another-class',
]
  .filter(Boolean)
  .join(' ')

Enter fullscreen mode Exit fullscreen mode

Written on a mobile so forgive any typos!