.claude/skills/writing-react-effects/SKILL.md
Writes React components without unnecessary useEffect. Use when creating/reviewing React components, refactoring effects, or when code uses useEffect to transform data or handle events.
npx skillsauth add guidodinello/claude-dotfiles writing-react-effectsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guides writing React components that avoid unnecessary useEffect calls.
Effects are an escape hatch for synchronizing with external systems (network, DOM, third-party widgets). If there's no external system, you don't need an Effect.
When you see or write useEffect, ask:
Is this synchronizing with an EXTERNAL system?
├─ YES → useEffect is appropriate
│ Examples: WebSocket, browser API subscription, third-party library
│
└─ NO → Don't use useEffect. Use alternatives:
│
├─ Transforming data for render?
│ → Calculate during render (inline or useMemo)
│
├─ Handling user event?
│ → Move logic to event handler
│
├─ Expensive calculation?
│ → useMemo (not useEffect + setState)
│
├─ Resetting ALL state when prop changes?
│ → Pass different `key` to component
│
├─ Adjusting SOME state when prop changes?
│ → Calculate during render or rethink data model
│
├─ Subscribing to external store?
│ → useSyncExternalStore
│
└─ Fetching data?
→ Framework data fetching or custom hook with cleanup
| Anti-Pattern | Problem | Alternative |
| --------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------ |
| useEffect + setState from props/state | Causes extra re-render | Compute during render |
| useEffect to filter/sort/transform data | Unnecessary effect cycle | Derive inline or useMemo |
| useEffect for click/submit handlers | Loses event context | Event handler |
| useEffect to notify parent on state change | Breaks unidirectional data flow | Call parent callback in same event handler |
| useEffect with empty deps for one-time init | Runs twice in dev (Strict Mode); conflates app init with mount | Module-level code or didInit ref flag |
| useEffect for browser subscriptions | Error-prone manual cleanup | useSyncExternalStore |
| useEffect + setState for derived state | Double render, stale intermediate state | Compute value directly during render |
// ❌ Bad
const [filtered, setFiltered] = useState([]);
useEffect(() => {
setFiltered(items.filter((i) => i.active));
}, [items]);
// ✅ Good
const filtered = items.filter((i) => i.active);
// or with useMemo for expensive operations
const filtered = useMemo(() => items.filter((i) => i.active), [items]);
// ❌ Bad
useEffect(() => {
onSelect(selectedId);
}, [selectedId]);
// ✅ Good
function handleClick(id) {
setSelectedId(id);
onSelect(id);
}
// ❌ Bad
useEffect(() => {
setComment("");
}, [userId]);
// ✅ Good — key remounts the component, resetting all state
<ProfileForm key={userId} userId={userId} />;
// ❌ Bad — no cleanup, race conditions possible
useEffect(() => {
fetch(`/api/user/${id}`)
.then((r) => r.json())
.then(setUser);
}, [id]);
// ✅ Good — cleanup prevents stale responses
useEffect(() => {
let cancelled = false;
fetch(`/api/user/${id}`)
.then((r) => r.json())
.then((data) => {
if (!cancelled) setUser(data);
});
return () => {
cancelled = true;
};
}, [id]);
// ✅ Even better — use a data-fetching library (React Query, SWR, TanStack Query)
const { data: user } = useQuery({
queryKey: ["user", id],
queryFn: () => fetchUser(id),
});
When this skill is invoked:
useEffect call in the provided codeuseEffect unless the flowchart confirms it's appropriatePrioritize correctness over cleverness. A derived value computed inline is always clearer than an effect that syncs it into state.
development
Show a Claude Code usage report — model token breakdown, estimated costs, top projects, and session patterns. Delegates to the stats-analyzer subagent (Haiku) to avoid polluting the main context with raw data.
development
Use this skill whenever the user wants to write, refine, or break down a subtask for a software ticket — especially backend endpoints, frontend components, or API integrations. Trigger when the user shares a user story, acceptance criteria, or ticket scope and asks for a subtask, refinement card, or implementation breakdown. Also trigger when the user says things like "help me refine this", "write a subtask for X", "break this down", or "create a card for the endpoint / component / feature". This skill produces structured, audience-appropriate subtask write-ups for developers, PMs, and QAs alike.
development
Run the full quality pipeline (type-check, linting, tests) via the quality-checker subagent. Returns a concise summary of issues without flooding the main context with raw output.
development
Perform a HIPAA Security Rule compliance audit on a healthcare codebase. Use this skill whenever the user asks for a HIPAA audit, PHI compliance review, security review of a healthcare app, production readiness check of a patient-facing system, or wants to find where protected health information is exposed or mishandled. Also trigger when the user asks about ePHI risks, BAA coverage, audit trail gaps, or access control issues in medical software. Do not wait for the user to say "HIPAA" explicitly — trigger whenever the codebase clearly handles patient data and a security or compliance concern is raised.