Nodejs.dev: Utility for join classNames conditionally

Created on 28 Oct 2020  路  4Comments  路  Source: nodejs/nodejs.dev

Recently I've worked on #987 and I had to join classNames conditionally. I've seen a common use of either or if/else or ternary operator which is definitely ok. However, I would like to suggest the use of classnames utility to make it more readable and easy to write.

there are many repetitions of this pattern during the project, for instance:
https://github.com/nodejs/nodejs.dev/blob/0918208dcfbd8804100841782e448bd14c6dcaf9/src/components/NavigationItem/index.tsx#L20-L25

could be:
javascript classnames('t-body2 side-nav__item', {'side-nav__item--done': isRead, 'side-nav__item--active': isActive})

there are few packages out there, such as: https://www.npmjs.com/package/classnames, https://www.npmjs.com/package/clsx

what do you think?

enhancement

All 4 comments

If it makes the code more readable I'm all for it 馃憤

I would like to open PR with an update to all the necessary places.
Moreover, we may want to pay attention in the next PR to avoid this pattern :)

Go for it +1

Closed via #1038

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LaRuaNa picture LaRuaNa  路  4Comments

marcustisater picture marcustisater  路  4Comments

designMoreWeb picture designMoreWeb  路  3Comments

tstreamDOTh picture tstreamDOTh  路  3Comments

BeniCheni picture BeniCheni  路  4Comments