You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The more I'm thinking about this, the more I think I should include clsx in tailwind-merge. My reasons:
clsx (or its pendant classnames) is probably already included in most projects using tailwind-merge. I have copied parts of clsx and inlined it in tailwind-merge to join strings, so adding it would have almost no impact on bundle size nor runtime performance.
I find the pattern of nested conditions with arrays in clsx really nice and often miss it in tailwind-merge. Basically this:
clsx('…',someBool&&['…',anotherBool&&'…'])
Prepending twMerge with clsx myself is not so nice DX-wise, even when using tailwind-merge with a custom config. It can even lead to anti-patterns.
// This feels a little weirdconsttwMergeInternal=extendTailwindMerge(…)exportconsttwMerge=(...args)=>twMergeInternal(clsx(args))// I really hope no one is doing this!exportconsttwMerge=(...args)=>extendTailwindMerge(…)(clsx(dontDoThis!))
I think I'll give it a shot. And if it turns out not to be a good idea, I think tailwind-merge should go into the opposite direction in a v2 update and only accept a single string as argument. This way the user could choose their own string-joining lib and tailwind-merge would leave the weird middle ground it is on right now.
From discussion:
The more I'm thinking about this, the more I think I should include clsx in tailwind-merge. My reasons:
clsx (or its pendant classnames) is probably already included in most projects using tailwind-merge. I have copied parts of clsx and inlined it in tailwind-merge to join strings, so adding it would have almost no impact on bundle size nor runtime performance.
I find the pattern of nested conditions with arrays in clsx really nice and often miss it in tailwind-merge. Basically this:
Prepending twMerge with clsx myself is not so nice DX-wise, even when using tailwind-merge with a custom config. It can even lead to anti-patterns.
I think I'll give it a shot. And if it turns out not to be a good idea, I think tailwind-merge should go into the opposite direction in a v2 update and only accept a single string as argument. This way the user could choose their own string-joining lib and tailwind-merge would leave the weird middle ground it is on right now.
Originally posted by @dcastil in #121 (reply in thread)
The text was updated successfully, but these errors were encountered: