No slash command · from web-tasuke
Rules for useEffect usage in React including when to avoid it and when to extract it into custom hooks. Use when writing or reviewing React components that contain or might need useEffect.
Ships in web-tasuke. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
useEffectは外部システム(ブラウザAPI、ネットワーク、サードパーティライブラリ)との同期にのみ使います。
それ以外の用途では、より適切な代替手段がないか検討してください。
参考: You Might Not Need an Effect
// Bad: useEffectでstateを更新
const [fullName, setFullName] = useState("");
useEffect(() => {
setFullName(firstName + " " + lastName);
}, [firstName, lastName]);
// Good: レンダリング中に計算
const fullName = firstName + " " + lastName;
// Bad: useEffectで副作用を検知
useEffect(() => {
if (product.isInCart) {
showNotification(`Added ${product.name} to cart!`);
}
}, [product]);
// Good: イベントハンドラで直接処理
function handleBuyClick() {
addToCart(product);
showNotification(`Added ${product.name} to cart!`);
}
// Bad: useEffectでリセット
useEffect(() => {
setComment("");
}, [userId]);
// Good: keyでコンポーネントを再マウント
<Profile userId={userId} key={userId} />;
// Bad: useEffectで計算結果をstateに保存
useEffect(() => {
setFilteredTodos(getFilteredTodos(todos, filter));
}, [todos, filter]);
// Good: useMemoでキャッシュ
const filteredTodos = useMemo(() => getFilteredTodos(todos, filter), [todos, filter]);
// Bad: useEffectで手動フェッチ(冗長なボイラープレート、キャッシュなし、重複排除なし)
useEffect(() => {
let ignore = false;
fetchData(id).then((data) => {
if (!ignore) setData(data);
});
return () => {
ignore = true;
};
}, [id]);
// Good: TanStack Query等を使う
const result = useSuspenseQuery({ queryKey: ["data", id], queryFn: () => fetchData(id) });
IntersectionObserver、ResizeObserverなど)これらの場合でも、 より高抽象度なhooksやライブラリが使えないか検討してください。
コンポーネント本体にuseEffectを直接書くことは禁止です。
必ずカスタムフックに切り出し、コンポーネント側はそのフックを呼ぶだけにしてください。
カスタムフックには責務を表す名前をつけます。
useDocumentTitle, useWindowResize, useDeviceListSubscriptionなど。
フックの配置場所はプロジェクトの規約に従ってください。
典型的にはsrc/hooks/のような共有ディレクトリか、
そのコンポーネントに固有のものであれば同じディレクトリの別ファイルに置きます。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
17 skills in this plugin
/any-typeAvoid using any type in TypeScript. Use unknown, generics, or proper type definitions instead. Use when writing or reviewing TypeScript type annotations./aria-usageWAI-ARIA usage guidelines. Avoid redundant ARIA attributes. No ARIA is better than Bad ARIA. Use when writing or reviewing HTML/JSX with accessibility attributes./as-const-satisfiesUse `as const` and `as const satisfies Type` for constant definitions in TypeScript. Use when defining constants, config objects, or string union types./async-state-typeAvoid contradictory state types for async data fetching. Use Suspense or discriminated unions instead. Use when writing or reviewing async data fetching code in React/TypeScript./avoid-forAvoid for loops (C-style, for...of, for...in) in TypeScript/JavaScript. Prefer higher-order Array methods like map, filter, find, some, every, reduce. Use when writing or reviewing loops or iteration over arrays, objects, Map, Set, or String./dynamic-importPrefer static import over dynamic import() in TypeScript/JavaScript. Use when writing or reviewing import statements.npx claudepluginhub ncaq/konoka --plugin web-tasuke