본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)9.7k · #12213

no-use-effect

하는 일

이 가이드는 버그와 불필요한 렌더링을 자주 일으키는 흔한 React 패턴에서 에이전트를 멀어지게 합니다. React 컴포넌트와 훅을 쓰거나 검토하는 개발자를 위한 가이드입니다.

사용하는 경우

  • ✓에이전트가 새 React 컴포넌트나 훅을 만들 때.
  • ✓기존 useEffect 호출을 리팩터링할 때.
  • ✓풀 리퀘스트가 useEffect를 추가해서 검토하고 싶은 경우.

스킬 링크

https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 React 컴포넌트를 검토하고, 실제로 필요하지 않은 useEffect를 제거해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 먼저 각 effect가 왜 있는지 묻고, 맞는 가장 단순한 패턴으로 바꿉니다. 렌더링 중에 값을 계산하기, 데이터 가져오기에 데이터 라이브러리 쓰기, 사용자 동작은 이벤트 핸들러에서 처리하기, 진짜 일회성 설정에는 좁은 훅을 쓰기가 포함됩니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

No useEffect

Never call useEffect directly unless the work is a true mount-only sync with an external system and no simpler pattern fits. Prefer a render-time computation, a query or mutation hook, an event handler, or a remount boundary instead.

Workflow

  1. Classify why the effect exists.
  2. Replace it with the narrowest pattern below.
  3. Verify with the project's normal lint, typecheck, and tests.

Replacement Patterns

1. Derive state, do not sync it

Replace useEffect(() => setX(derive(y)), [y]) with inline computation or the project's existing memoization conventions.

const filteredProducts = products.filter((product) => product.inStock);

Smell test: state only mirrors props or other state.

2. Use query or mutation libraries for async work

Replace fetch-in-effect code with the app's data layer.

const productQuery = useQuery({
  queryKey: ["product", productId],
  queryFn: () => fetchProduct(productId),
});

Smell test: the effect fetches, awaits, retries, cancels, or writes async results into local state.

3. Use event handlers for user actions

Do the work where the action happens instead of setting a flag and reacting later.

const handleLike = () => {
  postLike();
};

Smell test: state exists only to trigger an effect, then gets reset.

4. Use useMountEffect for mount-only external sync

Use this only for work that is naturally "set up on mount, clean up on unmount": DOM integration, subscriptions, third-party widgets, and stable singleton bindings.

If the project already has a useMountEffect, use it. If not, add a small wrapper:

import { useEffect } from "react";

export function useMountEffect(effect: () => void | (() => void)) {
  useEffect(effect, []);
}

Prefer changing component structure so the component only mounts once preconditions are satisfied.

Smell test: the effect is a one-time setup or teardown for something outside React.

5. Use key to reset component state

If a component should behave like a fresh instance when an ID or entity changes, remount it from the parent.

return <VideoPlayer key={videoId} videoId={videoId} />;

Smell test: the effect exists only to reset local state when props change.

Review Standard

Treat new direct useEffect usage as a bug by default. Ask which of the five patterns applies. Accept direct useEffect only with explicit justification that the code is a mount-only external sync and that useMountEffect is the intended escape hatch.

Structure React Code This Way

Order component logic like this:

  1. Hooks that read external state or data.
  2. Local state.
  3. Derived values computed during render.
  4. Event handlers.
  5. Early returns.
  6. Render output.

Do not introduce mirrored state just to make an effect possible.

자주 묻는 질문

useEffect는 언제 허용되나요?

마운트 시 한 번 실행되는 외부 시스템과의 진짜 동기화에만, 더 단순한 패턴이 맞지 않을 때만 허용됩니다.

앱 동작이 바뀌나요?

동작을 그대로 유지하는 것을 목표로 하며, 가이드는 이후에 일반 린트, 타입, 테스트 점검을 실행하라고 요청합니다.

파생 값이란 무엇인가요?

다른 값들로부터 렌더링 중에 계산되는 값으로, 별도의 상태 변수에 복사하지 않은 값입니다.

상세 정보

작성자의 원본 설명

Avoid direct React `useEffect` usage when writing or reviewing React components and hooks. Use this skill when creating new React code, refactoring existing `useEffect` calls, reviewing PRs that introduce `useEffect`, or when an agent reaches for `useEffect` as a default. Replace effects with derived state, query or mutation libraries, event handlers, `useMountEffect` for mount-only external sync, or `key`-based remounts.

repo: fastrepl/anarlog

인기도

GitHub 스타
9.7k
순위
#12213
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬