Undefined class name gets printed
just-boris opened this issue · 2 comments
just-boris commented
I have this code
import styles from './styles.css';
clsx({[styles.active]: isActive}); // returns "undefined" when `styles.active` is undefined
Ideally this should work the same way as this code: clsx(isActive && styles.active)
just-boris commented
A possible fix would be to extend this line:
Line 18 in 74cefa6
-if (mix[k]) {
+if (mix[k] && mix[k] != 'undefined') {
But I am not sure if it is an acceptable size increase for the library
lukeed commented
This is intentional & matches classnames
behavior.
As you've seen, when the key is evaluated, it's the string "undefined", which could very well be an intended classname as it's also valid.