lukeed / clsx

A tiny (239B) utility for constructing `className` strings conditionally.
MIT License
8.28k stars 143 forks source link

a dedupe version? #13

Closed deviprsd closed 5 years ago

deviprsd commented 5 years ago

A possible dedupe version so that classes aren't repeated twice?

lukeed commented 5 years ago

Hey, I don't think so 🙈 While it's certainly easy to implement, I've not actually seen a need for this in apps. It's also easy to implement yourself the 1 time (out of 500) you might actually need this.

Mostly I want to avoid the complexity of shipping multiple entry points, all with multiple formats... because the one time you or a coworker adds an import to clsx/dedupe, you now have two different copies of clsx floating around in your bundle.

Hoping I explained that well enough – the verbal side of my head isn't working today~ Closing for now, Thanks!

dy commented 5 years ago

Stumbled upon the same. Dedupe version is actually really useful for cases, when we deal with existing components, not react, where we create component from scratch each time. Eg. that would enable

el.classList.value = clsx(...Array.from(el.classList), ...additionalClasses)