finds.dev

lukeed/clsx

A tiny (239B) utility for constructing `className` strings conditionally.

View on GitHub

★ 9,823JavaScriptMITupdated Jun 2024

// the take

clsx is a 239-byte utility that merges class name strings conditionally, accepting strings, objects, and arrays in any combination. It's a drop-in replacement for the older `classnames` package, faster and about half the size. If you're doing any conditional className work in React or similar, this is the standard tool.

Ships three formats (ESM, CJS, UMD) so it works everywhere without configuration. The `clsx/lite` variant at 140 bytes is a meaningful optimization if you only use string arguments — worth knowing it exists. Handles deeply nested arrays without breaking, which saves you from flattening before calling. TypeScript types are included and correct.

The 239B size is the headline, but the actual gain over `classnames` in a real bundle is negligible — you're not choosing this for bytes saved. The `clsx/lite` module silently ignores non-string inputs instead of throwing, which will bite someone passing an object by mistake and getting an empty string with no error. Last meaningful commit was 2024 and there's nothing left to add, so maintenance is effectively in maintenance-only mode — fine for this scope, but worth knowing.

We read the README, the directory tree and a key source file in July 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
9,823
Forks
187
Language
JavaScript
License
MIT
Last commit
10 Jun 2024

// nearby

If clsx isn't quite it.

All repos →