lukeed / clsx

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

Supporting unwanted undefined in object #61

Closed TommySorensen closed 1 year ago

TommySorensen commented 1 year ago

Is there any plans for supporting this use case?

clsx({undefined: false});

Will return undefined which is unwanted.

Im using clsx in a React.js solution with CSS Modules like this:

 <section
      className={clsx(
        styles.test,
        { [styles[someOtherThing!]]: !!someOtherThing }
      )}
    >

In this case someOtherThing can be undefined or null and since i am doing !!someOtherThing then clsx should never return the "undefined" value.

lukeed commented 1 year ago

It wouldn’t show up with false, so here !!someOtherThing is evaluating to true. And “undefined” is always a string when used as a key name. See #40 for more explanation — it’s native JS and is due to the [undefined]: true syntax