`${ false ? '' : 'foo-bar'}` // => ''
this should return 'foo-bar' instead of ''.
For simple use cases classnames is definitely an overkill, but I would say if you have more than 2 conditions in the same template literal it becomes ugly really quickly.
classnames
Also there is a smaller package for the same purpose called clsx.
clsx
Thanks, correction made. Yes, agreed that it could get unwieldy, just showing another way of doing things is all. 😉
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
this should return 'foo-bar' instead of ''.
For simple use cases
classnamesis definitely an overkill, but I would say if you have more than 2 conditions in the same template literal it becomes ugly really quickly.Also there is a smaller package for the same purpose called
clsx.Thanks, correction made. Yes, agreed that it could get unwieldy, just showing another way of doing things is all. 😉