jorgebucaran / classcat

Build a class attribute string quickly
MIT License
905 stars 22 forks source link

React generates empty classnames in DOM if value is an empty string #30

Closed vladshcherbin closed 5 years ago

vladshcherbin commented 5 years ago

Same as https://github.com/JedWatson/classnames/issues/182

In react, if the value passed to className is an empty string, the html output will be <div class=""/>. In order to have a clean <div />, undefined should be passed.

Any idea how this can be solved? There is a PR in classnames, what do you think about this in classcat? :)

jorgebucaran commented 5 years ago

@vladshcherbin Can <div class=""/> break an app?

Hyperapp's output is: <div class /> by the way.

vladshcherbin commented 5 years ago

@jorgebucaran I don't think it can break an app.

Returning undefined just gives a clean html output without empty classes.

jorgebucaran commented 5 years ago

@vladshcherbin Return undefined and you may also end up with "undefined my-class" if you're concatenating Classcat's output with a string as someone already pointed out in the classNames PR.

React, Hyperapp should solve this, not Classcat. I want a clean DOM too, but changing Classcat to monkey-patch a JavaScript framework is worse.

I'll fix this in Hyperapp in https://github.com/jorgebucaran/hyperapp/issues/754.

Thanks! 👋

vladshcherbin commented 5 years ago

@jorgebucaran sure, thanks :)