no-use-effect
БесплатноБез исполняемых скриптовНе проверенNo direct useEffect in React components: derive state, use event handlers, Server Components, use(), key resets, useSyncExternalStore, useEffectEvent or…
от prowler-cloud★ 15 363 звезды на GitHubОб этом скилле
No Direct useEffect
Components never call useEffect directly. Most effects should not exist: the value can be derived in render, the work belongs in an event handler, or the data comes from the server. For the rare real sync with an external system, use a named hook.
Prowler UI Context
- React 19.2 with the React Compiler (
reactCompiler: trueinui/next.config.js). Never writeuseMemo,useCallbackormemo; lint rejects them. - Data comes from Server Components and server actions. There is no client data-fetching library: pass data (or a promise unwrapped with
use()) from the server instead of fetching in an effect. useMountEffectlives inui/hooks/use-mount-effect.ts.useEffectEventis stable (seeui/components/registry/use-registry-refresh.ts).useSyncExternalStoreexample:ui/hooks/use-media-query.ts.- Lint enforces part of this (
react-hooks/set-state-in-effect,react-hooks/refs,react-hooks/purity). Existing violations are frozen inui/eslint-suppressions.json; do not add new entries. - Effects that sync with a real external system are fine inside a named hook:
EventSource,matchMedia,ResizeObserver, timers, third-party widgets. Moving avoidable state sync into a custom hook is not a fix.
// ui/hooks/use-mount-effect.ts
export function useMountEffect(effect: EffectCallback) {
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(effect, []);
}
The 6 Rules
Rule 1: Derive state, do not sync it
If it can be calculated from existing state or props, compute it in render. The compiler caches it.
// BAD: two renders, and the copy drifts
const [visible, setVisible] = useState([]);
useEffect(() => {
setVisible(findings.filter((f) => !f.muted));
}, [findings]);
// GOOD
const visible = findings.filter((f) => !f.muted);
State that refers to server data stores only the user's intent (an id) and derives the effective value in render.
Smell test: useEffect(() => setX(f(y)), [y]), or state that only mirrors props, search params or query results.
Rule 2: Fetch on the server, not in effects
Effect-based fetching races and reinvents caching. Fetch in the Server Component (or a server action) and pass the result down. To stream, pass the promise and unwrap it with use() inside <Suspense>.
// GOOD: Server Component
export default async function Page() {
const providers = await getProviders();
return <ProvidersTable providers={providers} />;
}
// GOOD: client child unwraps a promise passed from the server
function Overview({ overviewPromise }: { overviewPromise: Promise<Overview> }) {
const overview = use(overviewPromise);
return <OverviewCards overview={overview} />;
}
Smell test: an effect that calls fetch() or a server action and then setState().
Rule 3: Event handlers, not effects
If a user action triggers it, do the work in the handler. Validate, transform, submit, then update state, all in the handler.
// BAD: flag relay through an effect
const [submitted, setSubmitted] = useState(false);
useEffect(() => {
if (submitted) {
saveRule(values);
setSubmitted(false);
}
}, [submitted]);
// GOOD
const handleSubmit = async () => {
await saveRule(values);
};
Shared logic between handlers is a function, not an effect.
Smell test: state used as a flag so an effect can do the real work.
Rule 4: useMountEffect for one-time external sync
Only for real mount-time setup with an external system. Gate the mount instead of guarding inside the effect.
// BAD: guard inside the effect
useEffect(() => {
if (!isLoading) startTour();
}, [isLoading]);
// GOOD: mount when ready
function TourGate({ isLoading }: { isLoading: boolean }) {
if (isLoading) return <TourSkeleton />;
return <Tour />;
}
function Tour() {
useMountEffect(() => startTour());
return null;
}
Smell test: the behavior is "set up on mount, clean up on unmount" with something outside React.
Rule 5: Reset with key, not dependency choreography
To start fresh when an id changes, remount with key. ui/app/(prowler)/lighthouse/page.tsx keys the chat by session this way.
// BAD
useEffect(() => {
setDraft("");
setSelection([]);
}, [sessionId]);
// GOOD
<ChatPanel key={sessionId} sessionId={sessionId} />
Smell test: the effect's only job is resetting local state when a prop changes.
Rule 6: Never patch a broken effect with a ref
A ref that stops an effect from double-firing, looping or reading stale state hides the real problem. Remove the effect.
// BAD: ref guard
const hasRun = useRef(false);
useEffect(() => {
if (hasRun.current) return;
hasRun.current = true;
trackPageView(page);
}, [page]);
// GOOD
useMountEffect(() => trackPageView(page));
// BAD: ref to read the latest callback
const onMessageRef = useRef(onMessage);
onMessageRef.current = onMessage;
useEffect(() => {
const source = new EventSourc
Установить no-use-effect в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadEditWriteGlobGrepBashВложенные файлы
FAQ
Что делает скилл no-use-effect?
No direct useEffect in React components: derive state, use event handlers, Server Components, use(), key resets, useSyncExternalStore, useEffectEvent or useMountEffect instead. React Compiler aware (no useMemo/useCallback). Trigger: When writing, editing or reviewing React components or hooks in ui/, when about to write useEffect or useLayoutEffect, or when syncing state with props, URL params or loaded data.
Как установить скилл no-use-effect?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл no-use-effect запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic