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
Hi there, I'm using a css-in-js library (stitches) which returns class names as objects with custom toString methods. This requires calling toString before passing the "class names" to clsx- otherwise clsx assumes the object is a config/mapping object.
// Current usageconstpink=css({color: "pink"});clsx(pink().toString())
I currently have a patch package which adds an additional check to the toVal function, checking to see if a mix object has it's own toString method and calls/returns that if so.
// General ideaif(mix.hasOwnProperty("toString")){str+=mix.toString();}
I noticed that classnames has a condition for this (original PR). React also calls toString if you pass an object to className. I'm wondering if it might be useful to include this behavior in clsx? I can contribute a PR if so.
The text was updated successfully, but these errors were encountered:
it might be worth looking into a codemod to automatically call the stitches' toString() method. For example, it could definitely be worked into the clsx babel plugin.
Strings are always the best (as in most performant) path for clsx to operate, so our current usage is definitely the preferred approach. Adding a toString check to clsx itself would be a significant performance hit (and byte size, percentage-wise). And your hasOwnProperty example snippet wouldn't suffice as it wouldnt cover class instances that have a toString method on its prototype.
Hi there, I'm using a css-in-js library (stitches) which returns class names as objects with custom
toString
methods. This requires callingtoString
before passing the "class names" toclsx
- otherwiseclsx
assumes the object is a config/mapping object.I currently have a patch package which adds an additional check to the
toVal
function, checking to see if amix
object has it's owntoString
method and calls/returns that if so.I noticed that
classnames
has a condition for this (original PR). React also callstoString
if you pass an object toclassName
. I'm wondering if it might be useful to include this behavior inclsx
? I can contribute a PR if so.The text was updated successfully, but these errors were encountered: