Note Inline styles use camelCase property names and string/number values. They cannot handle pseudo-classes (:hover), media queries, or keyframe animations. Best for truly dynamic values that change at runtime.
// With clsx or classnames libraryimport clsx from'clsx';
<div className={clsx('base', { active: isActive, disabled: isDisabled })} />
example
// Using the clsx libraryimport clsx from'clsx';
function StatusChip({ status }) {
return (
<span
className={clsx('chip', {
'chip--success': status === 'active',
'chip--warning': status === 'pending',
'chip--danger': status === 'error',
'chip--muted': status === 'inactive',
})}
>
{status}
</span>
);
}
// Without a libraryfunction StatusChipManual({ status }) {
const chipClass = [
'chip',
status === 'active' && 'chip--success',
status === 'error' && 'chip--danger',
].filter(Boolean).join(' ');
return <span className={chipClass}>{status}</span>;
}
Note The clsx library (or classnames) accepts strings, objects, and arrays. Object keys are included when their value is truthy. It is lightweight (~228 bytes) and widely used in the React ecosystem.