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がスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このReactのコンポーネントをレビューして、本当は必要ない useEffect を取り除いてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、まず各エフェクトがなぜ存在するかを尋ね、それから当てはまる最もシンプルなパターンに置き換えます。レンダリング中に値を計算すること、データ取得にデータライブラリを使うこと、ユーザーの操作はイベントハンドラで扱うこと、本当に一度だけのセットアップには狭いフックを使うことなどです。
技術的な内容(元の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
- Classify why the effect exists.
- Replace it with the narrowest pattern below.
- 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:
- Hooks that read external state or data.
- Local state.
- Derived values computed during render.
- Event handlers.
- Early returns.
- Render output.
Do not introduce mirrored state just to make an effect possible.
よくある質問
useEffect はいつ使えますか?
マウント時に一度だけ動く、外部システムとの本当の同期のためだけで、もっとシンプルなパターンが合わない場合だけです。
アプリの動きは変わりますか?
動きを同じに保つことを目指します。ガイドは、その後で通常のlint、型、テストの確認を実行するよう求めます。
導出された値とは何ですか?
別の状態変数にコピーするのではなく、レンダリング中に他の値から計算される値です。
詳細
作者による元の説明
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
コメント
- …
このリポジトリの他のスキル
sqlite-schema-design
9.7kエージェントが、SQLite Syncのルールに従って、キー、デフォルト値、スキーマ変更を守りながら、デバイス間で同期するデータベースのテーブルを設計またはレビューできるよう支援します。
anarlog
9.7kエージェントが、Anarlogの会議メモ、要約、文字起こし、参加者、アクション項目を検索したり、ローカルの録音を取り込んだりできるよう支援します。
似ているスキル
angular-developer
280kエージェントがAngularのコードを作成し、プロジェクト構成についてアドバイスできるようにします。新しいプロジェクトの開始、コード部品の作成、パフォーマンスやアクセシビリティの改善に役立ちます。
frontend-a11y
280kエージェントが Web インターフェースを誰にとっても使いやすくするよう支援します。スクリーンリーダーやキーボード操作に対応し、サイトやアプリが適切に動作するようにします。
frontend-patterns
280kエージェントがフロントエンド開発の最新パターンを適用できるようにします。React と Next.js において、パフォーマンスの最適化、状態管理、ベストプラクティスの遵守を行います。