` — not `` 2. **Labels:** Every form input has a `` with matching `htmlFor`/`id` 3. **ARIA only when needed:** `aria-label` for icon-only buttons, `aria-live` for dynamic updates, `role="alert"` for errors 4. **Keyboard navigation:** All interactive elements reachable via Tab, activatable via Enter/Space 5. **Focus management:** Set focus to main content on route change, trap focus in modals 6. **Color contrast:** Minimum 4.5:1 for normal text, 3:1 for large text 7. **Alt text:** All `` tags have descriptive `alt` (or `alt=""` for decorative images) ## Examples ### User List Page with Search and Pagination ```tsx export default function UserListPage() { const [search, setSearch] = useState(""); const debouncedSearch = useDebounce(search, 300); const pagination = usePagination(); const { data, isPending } = useQuery( userQueries.list({ q: debouncedSearch, cursor: pagination.cursor }) ); return ( Users { setSearch(e.target.value); pagination.reset(); }} placeholder="Search users..." aria-label="Search users" /> {isPending ? : ( <> {data.hasMore && ( pagination.goToNext(data.nextCursor)}> Load more )} > )} ); } ``` ## Edge Cases - **Stale closures in hooks:** When using callbacks that reference state, use `useRef` for mutable values that change frequently, or include dependencies in useCallback/useEffect arrays. - **TanStack Query key collisions:** Structure keys hierarchically: `["users"]` for list, `["users", id]` for detail, `["users", { q, page }]` for filtered list. Use `queryOptions()` factory to centralize key definitions. - **Infinite re-renders:** Common causes: missing dependency arrays, creating new objects/arrays in render (wrap in `useMemo`), state updates in useEffect without proper conditions. - **Hydration mismatches:** Avoid rendering content that depends on browser-only APIs (window, localStorage) during initial render. Use `useEffect` or check `typeof window !== "undefined"`. - **Memory leaks:** Cancel async operations in useEffect cleanup. TanStack Query handles this automatically for queries. See `references/component-templates.md` for annotated component templates. See `references/tanstack-query-patterns.md` for CRUD query patterns.