Last active
November 6, 2020 09:13
-
-
Save audunolsen/c21c09db56283e70a5da8e1133f76db9 to your computer and use it in GitHub Desktop.
.048kB classnames npm module alternative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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