# @rapid-platform/use-composed-class-name

> Compose and memoize a list of non-falsy space-separated CSS class names from an array, or yields of a generator function.

Latest version **1.1.0** (published 2022-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rapid-platform/use-composed-class-name
pnpm add @rapid-platform/use-composed-class-name
yarn add @rapid-platform/use-composed-class-name
bun add @rapid-platform/use-composed-class-name
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-06-23 |
| First published | 2022-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tyler Watson |
| Maintainers | tylerwatson |

## Links

- npm: https://www.npmjs.com/package/@rapid-platform/use-composed-class-name
- Repository: https://github.com/rapid-platform/use-composed-class-name
- npm.io page: https://npm.io/package/@rapid-platform/use-composed-class-name

## Recent versions

- 1.1.0 (latest) — 2022-06-23
- 1.0.0 — 2022-06-23

## README

# React Hook &mdash; `useComposedClassName`

Compose and memoize a list of non-falsy space-separated CSS class names from an array, or yields of a generator function.

This library has no dependencies.

```ts
function useComposedClassName(classNameGenerator: string[] | (() => Generator<string, void, unknown>), deps?: React.DependencyList): string;
```

## Examples

JS Generator function
```ts
// returns "btn btn-primary" for non-active states and "btn btn-primary btn-active"
// for active states
const [active, setActive] = useState(false);
const className = useComposedClassName(function*() {
    yield 'btn';
    yield 'btn-primary';
    if (active) {
        yield 'btn-active';
    }
}, [active]);
```

Truthy items in an array
```ts
// returns "btn btn-primary" for non-active states and "btn btn-primary btn-active"
// for active states
const [active, setActive] = useState(false);
const className = useComposedClassName([
    'btn',
    'btn-primary',
    active && 'btn-active',
], [active]);
```

---
_Source: https://npm.io/package/@rapid-platform/use-composed-class-name · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
