useQwikMethodUsage
¥Summary
-
规则生效日期:
v2.2.6¥Rule available since:
v2.2.6 -
诊断类别:
lint/nursery/useQwikMethodUsage¥Diagnostic Category:
lint/nursery/useQwikMethodUsage -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
-
¥Same as
qwik/use-method-usage
-
¥How to configure
{ "linter": { "rules": { "nursery": { "useQwikMethodUsage": "error" } } }}¥Description
禁止在 Qwik 应用中使用 component$ 之外的 use* 钩子或其他 use* 钩子。
¥Disallow use* hooks outside of component$ or other use* hooks in Qwik applications.
确保 Qwik 的生命周期钩子仅在有效的响应式上下文中使用。请参阅 Qwik 组件生命周期 获取正确的 hook 使用方法。
¥Ensures Qwik’s lifecycle hooks are only used in valid reactive contexts. See Qwik Component Lifecycle for proper hook usage.
¥Examples
¥Invalid
import { useSignal } from "@builder.io/qwik";
export const Counter = () => { const count = useSignal(0);};code-block.js:4:17 lint/nursery/useQwikMethodUsage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Qwik hook detected outside of an allowed scope.
3 │ export const Counter = () => {
> 4 │ const count = useSignal(0);
│ ^^^^^^^^^^^^
5 │ };
6 │
ℹ Qwik’s reactive hooks (functions starting with use* followed by uppercase letter) must be:
- Used exclusively within `component$` functions
- Or encapsulated within other valid Qwik hooks
ℹ Check the Qwik documentation.
¥Valid
import { component$, useSignal } from "@builder.io/qwik";
export const Counter = component$(() => { const count = useSignal(0);});
export const useCounter = () => { const count = useSignal(0); return count;};¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号