Back to Biomejs

useQwikClasslist

src/content/docs/linter/rules/use-qwik-classlist.mdx

latest6.8 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v2.1.4` - Diagnostic Category: [`lint/correctness/useQwikClasslist`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - This rule belongs to the following domains: - [`qwik`](/linter/domains#qwik) - Sources: - Same as [`qwik/prefer-classlist`](https://qwik.dev/docs/advanced/eslint/#prefer-classlist)

How to configure

json
{
	"linter": {
		"rules": {
			"correctness": {
				"useQwikClasslist": "error"
			}
		}
	}
}

Description

Prefer using the class prop as a classlist over the classnames helper.

This rule encourages the use of class prop which natively supports strings, objects, and arrays, enabling fine-grained reactivity and optimal performance. Using utilities like classnames can interfere with Qwik's reactivity model and prevent the framework from optimizing component updates. Prefer using the built-in class prop for best results.

For more information, see: Qwik documentation on class bindings

Examples

Invalid

jsx
<div class={classnames({ active: true, disabled: false })} />
<pre class="language-text"><code class="language-text">code-block.jsx:1:6 <a href="https://biomejs.dev/linter/rules/use-qwik-classlist">lint/correctness/useQwikClasslist</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Avoid third-party </span><span style="color: Tomato;"><strong>classnames</strong></span><span style="color: Tomato;"> utilities with Qwik components</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>&lt;div class=&#123;classnames(&#123; active: true, disabled: false &#125;)&#125; /&gt; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Qwik's built-in </span><span style="color: lightgreen;"><strong>class</strong></span><span style="color: lightgreen;"> prop handles: </span> <span style="color: lightgreen;">- Conditional classes via objects: </span><span style="color: lightgreen;"><strong>class=&#123;&#123; active: isActive &#125;&#125;</strong></span><span style="color: lightgreen;"> </span> <span style="color: lightgreen;">- Dynamic string concatenation </span> <span style="color: lightgreen;">- Array combinations </span> <span style="color: lightgreen;"> </span> <span style="color: lightgreen;">External utilities break Qwik's: </span> <span style="color: lightgreen;">- Fine-grained reactivity tracking </span> <span style="color: lightgreen;">- Resumability optimizations</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use native Qwik class binding as shown in </span><span style="color: lightgreen;"><a href="https://qwik.dev/docs/components/tasks/">Qwik Rendering: Class Bindings (Official Docs).</a></span> </code></pre>

Valid

jsx
<div class={{ active: true, disabled: false }} />
</TabItem> </Tabs>