skills/react-best-practices/SKILL.md
React 18+ conventions for this project — React Compiler (no manual memoization), ReactElement ambient type, useEffect comment rule, plain function declarations, file and import conventions. Use when authoring or editing any React component, hook, or page. Do NOT use for general TypeScript-only utilities with no React imports — load typescript-best-practices instead.
npx skillsauth add bkinsey808/songshare-effect react-best-practicesInstall 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.
Requires: file-read, terminal (linting/testing). No network access needed.
Full reference: /docs/client/react-best-practices.md
Companion skill (load on demand):
Depends on: manage-page-patterns/SKILL.md — load when the task involves admin/manage page mutations. supabase-client-patterns/SKILL.md — load when the task involves React-side Supabase queries.
docs/ai/rules.md for repo-wide constraints.Prefer required props — avoid many optional props; use noops/fallback refs at call sites instead of optional handlers. → full detail
No React.FC — use an explicit prop type and ): ReactElement return annotation.
→ full detail
ReactElement is ambient — do not import it; ReactNode must be imported.
→ full detail
Plain function declarations — use function handleClick(): void {} over arrow assignments for handlers and components.
→ full detail
useEffect comment — add a // comment on the line directly above every useEffect explaining why it exists.
→ full detail
Complete dependency arrays — do not suppress the exhaustive-deps lint rule; restructure instead. → full detail
No manual memoization — React Compiler handles optimization; never add useCallback, useMemo, or memo without documented justification and explicit user approval.
→ full detail
One component per file — colocate tests in the same directory. → full detail
Direct imports — no barrel index.ts re-exports; import from source files.
→ full detail
Write code changes directly. After edits, output a brief bullet list of which conventions were applied and why, and which validation commands were run. For question-answering: concise prose with inline code.
npm run lint or npx tsc -b . fails after changes, report verbatim and fix before declaring success.npm run lint
Input: "Remove the useCallback from this event handler in MyComponent.tsx"
Expected: Reads the file, removes useCallback wrapper, converts to function handle(): void {}, runs lint and tsc, reports what changed and that React Compiler handles memoization.
Input: "Add a useEffect that syncs selectedId to localStorage"
Expected: Adds useEffect with a // comment above it explaining why, includes selectedId in the dep array, runs lint. Does not add useCallback.
Input: "Write tests for useMyHook.ts"
Expected: Loads unit-test-hook-best-practices skill and proceeds per that skill's guidance, not this one.
unit-test-hook-best-practices.typescript-best-practices instead.manage-page-patterns.supabase-client-patterns.tools
Zustand state management patterns for this project — store creation, selectors, Immer middleware, async actions with loading states, devtools, persist, and testing. Use when authoring or editing Zustand stores (use*Store files) or components that subscribe to stores. Do NOT use for React component structure or TypeScript-only utilities.
testing
How to write, update, or split skill files in this repo. Use when creating a new SKILL.md, updating an existing one, or deciding whether to put content in a skill vs. docs/.
development
Complete guide for testing React hooks — renderHook, Documentation by Harness, installStore, fixtures, subscription patterns, lint/compiler traps, and pre-completion checklist. Read docs/testing/unit-test-hook-best-practices.md for the full reference.
development
Vitest unit test authoring for this repo — setup, mocking, API handler testing, and common pitfalls for non-hook code. Use when the user asks to add, update, fix, or review unit tests for utilities, components, API handlers, or scripts. Do NOT use for React hook tests — load unit-test-hook-best-practices instead.