classnames
Replacing classnames classnames(a, b, c)
Vanilla JavaScript
const isPrimary = true;
const isError = false;
// Native array filtering
const classList = [
'button',
isPrimary && 'primary',
isError && 'error',
'rounded'
].filter(Boolean).join(' ');
// output: "button primary rounded"
Why Use This?
Libraries like `classnames` or `clsx` are extremely popular in React loops, but an inline array with `.filter(Boolean).join(' ')` does exactly the same trick natively. It leverages short-circuit `&&` evaluations naturally.