Skip to content

useBem

useBem(element, modifiers?, options?): string

Defined in: useBem.js:40

Build a BEM class name for a component.

The block comes from options.block when given (a string, or false to make element a root), otherwise from context, and falls back to element itself at the root. The hook only reads the current block; it never re-roots the context for descendants — use withBem for that — so it’s safe to call anywhere, e.g. recomputing class names from async state without prop drilling.

Every entry in modifiers is applied: true--name, an array → one --name_item per item, false/null/undefined → skipped, anything else → --name_String(value) (a throwing toString is silently skipped).

string

Record<string, unknown> = {}

Modifier name → value; every entry is applied (the caller controls exactly which modifiers are set).

UseBemOptions = {}

string