--- name: react-code description: Applies GAIA's patterns and conventions for writing and editing React components and hooks. Use this skill whenever writing or reviewing React components, hooks, or event handlers, or deciding on component extraction. Also trigger when deciding whether a manual memo or "use no memo" is justified under React Compiler, debugging stale closures or infinite re-renders, weighing a new dependency against a web-platform API or a hand-rolled primitive, choosing a React 19 idiom, or reaching for React's form Actions instead of React Router's form handling. --- # React Code Write and edit React components, pages, routes, hooks, and forms following project conventions. Contents: Reach for the Platform First; Pre-Flight Gates; Memoization: compiler-first; Component Structure; Data Loading; Route-Page Architecture; References. ## Reach for the Platform First Before installing a package or hand-rolling a primitive, follow the reuse order in Simplicity First. On the frontend: - **Existing project code** covers form inputs (Gate 2); a project component wins over a native element, since a wrapper exists for a reason. - **Web platform** means a browser API or native element (`Intl`, `URL`, `structuredClone()`, ``, modern CSS). - **Installed dependency:** for component/hook traps Claude often hand-rolls (client-only/useHydrated, sse, debounce-fetcher), see the remix-utils decision map at `wiki/dependencies/remix-utils.md` before reinventing. ## Pre-Flight Gates Run each gate when its pattern appears in your changes. ### Gate 1: Hook Check **Before writing `useEffect`:** decide whether it should be an Effect at all. Lint (`react-you-might-not-need-an-effect`) reports the ones that should not: state derived from props or state, user-event logic, chained updates, notifying a parent, and resetting state on a prop change. An Effect is right when it synchronizes with an external system (browser API, third-party widget, network). Add cleanup (a fetch aborts its `AbortController`; a client that cannot cancel uses an `ignore` flag: `references/hook-patterns.md`). **Before writing `useMemo`, `useCallback`, or `memo`:** don't; see `## Memoization: compiler-first`. **`useState`:** for an absent initial value, prefer `undefined` over `null` (never-null convention): `useState()` is already typed `T | undefined`. ### Gate 2: Form Element Check **Before writing ``, `