Communitygithub.com

ComeOnOliver/skillshub

React useEffect 最佳實踐(擷取自官方文件)。在撰寫/審查 useEffect、為派生值使用 useState、資料擷取或狀態同步時使用。說明何時不該使用 Effect 及更佳替代方案。

skillshub 是什麼?

此技能提供基於 React 官方文件的 useEffect 最佳實務指南,重點在於協助開發者判斷何時不需要使用 Effect,並推薦更簡潔的替代方案。它涵蓋六種常見情境:派生狀態應在渲染時計算、昂貴計算用 useMemo、prop 變更時重設狀態用 key prop、使用者事件直接在事件處理常式中處理、通知父層變更也在事件處理常式中進行,以及資料擷取應包含清理函式或使用框架內建機制。技能明確區分 Effect 的必要用途(外部系統同步、外部 store 訂閱、分析日誌、資料擷取)與非必要情境(資料轉換、使用者事件、派生狀態、狀態更新鏈)。支援所有 React 專案,可整合至 Claude Code、Cursor 或 Codex 等開發工具中,協助團隊遵守官方推薦模式,減少不必要的 Effect 使用,提升元件效能與可維護性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/jarrodwatts/claude-code-config/react-useeffect

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

你可能不需要一個 Effect

Effect 是 React 的逃生艙。它們讓你與外部系統同步。如果沒有涉及外部系統,你就不應該需要 Effect。

快速參考

情境不要做請這麼做
從 props/state 派生狀態useState + useEffect在渲染時計算
昂貴的計算用 useEffect 來快取用 useMemo
prop 變更時重設狀態在 useEffect 中呼叫 setState使用 key prop
回應使用者事件用 useEffect 監聽 state 變化直接在事件處理常式中處理
通知父層狀態變更在 useEffect 中呼叫 onChange在事件處理常式中呼叫
擷取資料使用沒有清理函式的 useEffect使用有清理函式的 useEffect 或框架機制

何時確實需要 Effect

  • 與外部系統同步(非 React 的 widget、瀏覽器 API)
  • 訂閱外部 store(盡可能使用 useSyncExternalStore)
  • 因為元件顯示而觸發的分析/記錄
  • 有適當清理的資料擷取(或使用框架內建機制)

何時不需要 Effect

  1. 為渲染轉換資料 - 在頂層計算,會自動重新執行
  2. 處理使用者事件 - 使用事件處理常式,你確切知道發生了什麼
  3. 派生狀態 - 直接計算:const fullName = firstName + ' ' + lastName
  4. 鏈式狀態更新 - 在事件處理常式中一次計算所有下一個狀態

決策樹

需要對某件事做出反應?
├── 使用者互動(點擊、提交、拖曳)?
│   └── 使用**事件處理常式**
├── 元件出現在畫面上?
│   └── 使用**Effect**(外部同步、分析)
├── Props/state 變更且需要派生值?
│   └── **在渲染時計算**
│       └── 昂貴計算?使用 useMemo
└── 當 prop 變更時需要重設狀態?
    └── 在元件上使用 **key prop**

詳細指引

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能