v0.20.230 - 6.2 / 6

setClass

Imperative helper for assigning classes to an element. Accepts a string, an array, a {className: boolean} object, or a reactive accessor. Strings replace the full class attribute; arrays and objects add/remove individual classes.

# Signature

# Arguments

nametypedescription
nodeElementtarget element
valuestring | string[] | { className: boolean } | signala string sets class wholesale; array/object forms add truthy entries and remove falsy ones; functions are tracked reactively.

Returns: void

# When to use

JSX's class= and class:myClass= already flow through setClass. Use the function when building nodes imperatively, writing a propsPlugin, or driving a class from an effect outside JSX.

Related: class:__ covers the declarative forms.

# Snippet