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.

classnames lib - Object Syntax

See original GitHub issue

This isn’t a bug or a problem that requires fixing.

I noticed that this project uses classnames, which is great, but in many places the project is using ternary operators for toggling classes when the object style eliminates this need completely.

Example:

const componentClassnames = classnames([
  styles.component,
  isVisible ? styles.isVisible : null,
  flipHorizontal ? styles.flipHorizontal : null,
  flipVertical ? styles.flipVertical : null,
]);
  • could instead be
const componentClassnames = classnames(styles.component, {
    [styles.isVisible]: isVisible,
    [styles.flipHorizontal]: flipHorizontal,
    [styles.flipVertical]: flipVertical,
});

when classnames receives an object it concatenates the keys for any values that are true.

I think the latter reads much cleaner.

This isn’t critical but I figured it was worth mentioning. If there was a specific reason this style was avoided, then I apologize in advance. If this is something everyone likes, I will be happy to put together a PR for these changes.

Love all the work 🙂

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rvcascommented, Jul 17, 2019

@daniloprates yes I think so

1reaction
danilopratescommented, Jul 15, 2019

Ok changes are in #1465

@lrosa007 that’s an awesome contribution. Is the PR ready to be reviewed?

Thanks, Danilo

Read more comments on GitHub >

github_iconTop Results From Across the Web

classnames - npm
A simple utility for conditionally joining classNames together. Latest version: 2.3.2, last published: 3 months ago. Start using classnames ...
Read more >
You don't know the classNames library - Arek Nawo
The usefulness of the classNames library comes from its syntax. All it is is a single function, taking different types of values as ......
Read more >
classnames-bind.md - gists · GitHub
Thankfully, the classnames library ships with an alternative method for ... That syntax is the only way to reference object keys with disallowed...
Read more >
Classnames by JedWatson
A simple javascript utility for conditionally joining classNames together. Install with npm or Bower. ... The classNames function takes any number of arguments ......
Read more >
Using the classnames library for conditional CSS in React
Classnames is a simple yet versatile javascript utility that joins CSS class names based on a set of conditions.
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