New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-classset

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-classset

Utility for easily manipulating the DOM class string

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
553
increased by48.26%
Maintainers
2
Weekly downloads
 
Created
Source

react-classset

classSet() is a neat utility for easily manipulating the DOM class string. This previously resided inside React as a utility, but is now pulled out and library-agnostic.

Here's a common scenario

var classString = 'message';
if (isImportant) {
  classString += ' message-important';
}
if (isRead) {
  classString += ' message-read';
}

This can quickly get tedious, as assigning class name strings can be hard to read and error-prone. classSet() solves this problem:

var classString = classSet({
  'message': true,
  'message-important': isImportant,
  'message-read': isRead
});

When using classSet(), pass an object with keys of the CSS class names you might or might not need. Truthy values will result in the key being a part of the resulting string.

Alternatively, you can also use it this way:

cx('a', 0, null, undefined, 'b'); // 'a 0 b', discards null values

No more hacky string concatenations!

Keywords

FAQs

Package last updated on 31 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc