finds.dev← search

// the find

lukeed/clsx

★ 9,823 · JavaScript · MIT · updated Jun 2024

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

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.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →