classes

September 04, 2021

1 min read

views

Implementation

Add multiple classes that can also be type boolean, null and undefined.

src/util/classes.ts
export function classes(...arr: (string | boolean | null | undefined)[]): string {
  return arr.filter(Boolean).join(" ");
}

Usage

<div className={classes("myClass", isTrue && "anotherClass")}>Hello world!</div>