Return of empty string results in class=""
See original GitHub issueI can wrap this function in a comparison function and make className
undefined
myself, but was wondering if this was the best way. I’d looked through the issues and was surprised no one has raised this issue before.
In the real world, I’d probably wrap this library in a library level utility that does this and not repeat the object twice. This is of course specific to React which sees an empty string and undefined
differently.
className={classNames({
'slds-is-today': isToday,
'slds-disabled-text': !isCurrentMonth,
'slds-is-selected': isSelectedDay
}) === '' ? undefined : classNames({
'slds-is-today': isToday,
'slds-disabled-text': !isCurrentMonth,
'slds-is-selected': isSelectedDay
})
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:10
Top Results From Across the Web
c# - How to return an empty string? - Stack Overflow
Hi i know that i can return: partner = new Ansprechpartner(); My Problem ist that i working with a Webgrid. Ich partner ==...
Read more >String.IsNullOrEmpty(String) Method (System) - Microsoft Learn
Indicates whether the specified string is null or an empty string (""). ... Empty; return result; } string s1 = null; string s2...
Read more >Checking for Empty or Blank Strings in Java - Baeldung
We consider a string to be empty if it's either null or a string without any length. If a string only consists of...
Read more >Optional (Java Platform SE 8 ) - Oracle Help Center
If a value is present the result must include its string representation in the result. Empty and present Optionals must be unambiguously differentiable....
Read more >Empty Values - Std Lib - Scala Exercises
Scala's null is the same as in Java. Any reference type can be null , like Strings, Objects, or your own classes. Also...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had this exact same issue today haha! I’m like why the heck are there all these blank
class
attributes. I did this for now:file:
react-classnames
Excellent question, but unfortunately changing it would be API incompatible as many users use concatenation with other strings post-haste which would cause
"undefined"
to be concatenated if changed now.