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

no-use-effect

하는 일

이 스킬은 AI 에이전트에게 React의 useEffect 훅을 건너뛰고 더 안전한 대안을 쓰도록 가르칩니다. 디버그하기 쉬운 더 깔끔한 컴포넌트를 원하는 React 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓에이전트가 새 React 컴포넌트를 쓰려고 할 때.
  • ✓useEffect를 쓰는 코드를 검토하며 단순하게 만들고 싶을 때.
  • ✓에이전트가 혹시 몰라 useEffect를 추가했고 이를 없애고 싶은 경우.

스킬 링크

https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/no-use-effect/SKILL.md

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

사용 방법

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

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

Use this skill to help me: https://github.com/humanlayer/humanlayer/blob/main/.claude/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. Use derived state, event handlers, data-fetching libraries, or useMountEffect instead.

Quick Reference

This skill is dervied from the React docs: You Might Not Need an Effect. IMPORTANT: when this skill is invoked you MUST read this post in entirety.

Instead of useEffect for... Use
Deriving state from other state/props Inline computation (Rule 1)
Fetching data useQuery / data-fetching library (Rule 2)
Responding to user actions Event handlers (Rule 3)
One-time external sync on mount useMountEffect (Rule 4)
Resetting state when a prop changes key prop on parent (Rule 5)

When to Use This Skill

  • Writing new React components
  • Refactoring existing useEffect calls
  • Reviewing PRs that introduce useEffect
  • An agent adds useEffect "just in case"

Workflow

1. Identify the useEffect

Determine what the effect is doing -- deriving state, fetching data, responding to an event, syncing with an external system, or resetting state.

2. Apply the Correct Replacement Pattern

Use the five rules below to pick the right replacement.

3. Verify

bun --bun run typecheck -- --filter=<package>
bun --bun run test -- --filter=<package>

The Escape Hatch: useMountEffect

For the rare case where you need to sync with an external system on mount:

The implementation wraps useEffect with an empty dependency array to make intent explicit:

export function useMountEffect(effect: () => void | (() => void)) {
  /* eslint-disable no-restricted-syntax */
  useEffect(effect, []);
}

Replacement Patterns

Rule 1: Derive state, do not sync it

Most effects that set state from other state are unnecessary and add extra renders.

// BAD: Two render cycles - first stale, then filtered
function ProductList() {
  const [products, setProducts] = useState([]);
  const [filteredProducts, setFilteredProducts] = useState([]);

  useEffect(() => {
    setFilteredProducts(products.filter((p) => p.inStock));
  }, [products]);
}

// GOOD: Compute inline in one render
function ProductList() {
  const [products, setProducts] = useState([]);
  const filteredProducts = products.filter((p) => p.inStock);
}

Smell test: You are about to write useEffect(() => setX(deriveFromY(y)), [y]), or you have state that only mirrors other state or props.

Rule 2: Use data-fetching libraries

Effect-based fetching creates race conditions and duplicated caching logic.

// BAD: Race condition risk
function ProductPage({ productId }) {
  const [product, setProduct] = useState(null);

  useEffect(() => {
    fetchProduct(productId).then(setProduct);
  }, [productId]);
}

// GOOD: Query library handles cancellation/caching/staleness
function ProductPage({ productId }) {
  const { data: product } = useQuery(['product', productId], () =>
    fetchProduct(productId)
  );
}

Smell test: Your effect does fetch(...) and then setState(...), or you are re-implementing caching, retries, cancellation, or stale handling.

Rule 3: Event handlers, not effects

If a user clicks a button, do the work in the handler.

// BAD: Effect as an action relay
function LikeButton() {
  const [liked, setLiked] = useState(false);

  useEffect(() => {
    if (liked) {
      postLike();
      setLiked(false);
    }
  }, [liked]);

  return <button onClick={() => setLiked(true)}>Like</button>;
}

// GOOD: Direct event-driven action
function LikeButton() {
  return <button onClick={() => postLike()}>Like</button>;
}

Smell test: State is used as a flag so an effect can do the real action, or you are building "set flag -> effect runs -> reset flag" mechanics.

Rule 4: useMountEffect for one-time external sync

Good uses: DOM integration (focus, scroll), third-party widget lifecycles, browser API subscriptions.

// BAD: Guard inside effect
function VideoPlayer({ isLoading }) {
  useEffect(() => {
    if (!isLoading) playVideo();
  }, [isLoading]);
}

// GOOD: Mount only when preconditions are met
function VideoPlayerWrapper({ isLoading }) {
  if (isLoading) return <LoadingScreen />;
  return <VideoPlayer />;
}

function VideoPlayer() {
  useMountEffect(() => playVideo());
}

Use useMountEffect for stable dependencies (singletons, refs, context values that never c

자주 묻는 질문

무엇이 useEffect를 대체하나요?

인라인 계산, 데이터 가져오기 라이브러리, 이벤트 핸들러, 마운트 시 한 번 실행하는 훅, 상태를 초기화하는 key 프롭이 있습니다.

useEffect를 완전히 금지하나요?

네. useEffect를 직접 호출하지 말고 나열된 대안을 쓰라고 안내합니다.

조언은 어디에서 왔나요?

effect가 필요하지 않은 때에 대한 React 문서의 안내를 바탕으로 합니다.

상세 정보

작성자의 원본 설명

Enforce the no-useEffect rule when writing or reviewing React code. ACTIVATE when writing React components, refactoring existing useEffect calls, reviewing PRs with useEffect, or when an agent adds useEffect "just in case." Provides the five replacement patterns and the useMountEffect escape hatch.

repo: humanlayer/humanlayer

인기도

GitHub 스타
13k
순위
#11389
라이선스
Apache-2.0
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬