@serenity-is/corelib / useClassList
Function: useClassList()
useClassList(
initialValue?):BasicClassList
Defined in: ../domwise/dist/index.d.ts:2626
Creates a classList-like manager that can be used as a JSX prop hook for the class attribute.
The returned BasicClassList is a callable that also implements
add/remove/toggle/contains plus value/size, mirroring the native
DOMTokenList API. When assigned to class (e.g. <div class={cls} />),
the hook binds to the element's classList and keeps it in sync; the
binding is cleaned up automatically when the element is disposed.
Before binding, an optional initialValue is used to seed a detached
classList so that add/remove calls prior to attachment are preserved.
Parameters
initialValue?
Optional initial class value (string, array, dictionary, iterable, or DOMTokenList).
Returns
A BasicClassList instance that is both callable and a prop hook.
Example
const cls = useClassList("foo");
cls.add("bar");
return <div class={cls} />;