--- name: loom-react description: "Modern client-side React development patterns. Not for: a loom-hooks shell script or a stage's lifecycle state." triggers: - react - jsx - tsx - component - react hook - useState - useEffect - useContext - useReducer - useMemo - useCallback - useRef - props - render - virtual DOM - reconciliation - single page application - spa - react-router - jotai - vite - bun - oxc - oxlint - oxfmt - rolldown - react compiler - eslint - prettier - client-side routing - accessibility - a11y - ARIA - performance - code splitting - lazy loading - Suspense - error boundaries - form validation - UI components - design system - composition patterns --- # React SPA Development ## Overview Client-side React 19+ SPAs. Stack: **React Router v7** (routing/loaders), **Jotai** (atomic global state), **Vite** (build — Rolldown bundler, Oxc transforms and minifier, Lightning CSS), **oxlint** + **oxfmt** (lint/format — the Oxc replacements for ESLint and Prettier), **Bun** (package manager/runtime). NOT for SSR frameworks (Next.js/Remix) — those are out of scope. The single densest section is **Expert Practices** at the end — read it first if you know React basics. The middle sections are reference implementations. ## React 19 Features ### Actions and useActionState React 19 introduces Actions for handling async state transitions: ```typescript import { useActionState } from 'react' interface FormState { message: string error?: string } async function updateProfile(previousState: FormState, formData: FormData) { const name = formData.get('name') as string try { await fetch('/api/profile', { method: 'POST', body: JSON.stringify({ name }), }) return { message: 'Profile updated successfully' } } catch (error) { return { message: '', error: 'Update failed' } } } export function ProfileForm() { const [state, formAction, isPending] = useActionState(updateProfile, { message: '' }) return (
) } ``` ### useOptimistic for Instant UI Updates ```typescript import { useOptimistic, useState } from 'react' interface Todo { id: string title: string completed: boolean } export function TodoList({ todos }: { todos: Todo[] }) { const [optimisticTodos, addOptimisticTodo] = useOptimistic( todos, (state, newTodo: Todo) => [...state, newTodo] ) async function addTodo(formData: FormData) { const title = formData.get('title') as string const tempTodo = { id: crypto.randomUUID(), title, completed: false } addOptimisticTodo(tempTodo) await fetch('/api/todos', { method: 'POST', body: JSON.stringify({ title }), }) } return (