Back to Biomejs

noVueSetupPropsReactivityLoss

src/content/docs/linter/rules/no-vue-setup-props-reactivity-loss.mdx

latest3.3 KB
Original Source

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

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.2.6` - Diagnostic Category: [`lint/correctness/noVueSetupPropsReactivityLoss`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - 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: - [`vue`](/linter/domains#vue) - Sources: - Inspired from [`vue/no-setup-props-reactivity-loss`](https://eslint.vuejs.org/rules/no-setup-props-reactivity-loss)

How to configure

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

Description

Disallow destructuring of props passed to setup in Vue projects.

In Vue's Composition API, props must be accessed as props.propertyName to maintain reactivity. Destructuring props directly in the setup function parameters will cause the resulting variables to lose their reactive nature.

Examples

Invalid

js
export default {
  setup({ count }) {
    return () => h('div', count);
  }
}
<pre class="language-text"><code class="language-text">code-block.js:2:9 <a href="https://biomejs.dev/linter/rules/no-vue-setup-props-reactivity-loss">lint/correctness/noVueSetupPropsReactivityLoss</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Destructuring &#96;props&#96; in the &#96;setup&#96; function parameters loses reactivity.</span> <strong>1 │ </strong>export default &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> setup(&#123; count &#125;) &#123; <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>3 │ </strong> return () =&gt; h('div', count); <strong>4 │ </strong> &#125; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">To preserve reactivity, access props as properties: &#96;props.propertyName&#96;.</span> </code></pre>

Valid

js
export default {
  setup(props) {
    return () => h('div', props.count);
  }
}
</TabItem> </Tabs>