Skip to content

Instantly share code, notes, and snippets.

@audunolsen
Last active November 6, 2020 09:13
Show Gist options
  • Save audunolsen/c21c09db56283e70a5da8e1133f76db9 to your computer and use it in GitHub Desktop.
Save audunolsen/c21c09db56283e70a5da8e1133f76db9 to your computer and use it in GitHub Desktop.
.048kB classnames npm module alternative
/*
the npm module "classnames" has 5,549,574 weekly downloads
as of 06.11.2020. It has an unpacked size of 16.3 kB.
Why TF is such a trivial package so popular given its size?
Here's a 0.048 kB alternative:
*/
export default c => c.filter(Boolean).join(" ");
// Usage example:
import c from "./utils/classnames.js";
<div className={c([
"box", // No condition
this.state.isActive && "active", // Conditional
this.state.isLarge ? "large" : "small" // Toggle
])}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment