question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return of empty string results in class=""

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:10

github_iconTop GitHub Comments

1reaction
Noitidartcommented, Mar 6, 2017

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

// classnames returns blank string when it fails, it should be returned undefined for react
import classnames from 'classnames';

const classnamesUndefined = (...args) => classnames(...args) || undefined;

export default classnamesUndefined;
1reaction
dcousenscommented, Mar 4, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found