Skip to content

useQwikMethodUsage

¥Summary

¥How to configure

biome.json
{
"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