Skip to content

React Development Recipes

React development recipes in this cookbook are copy-paste prompts for building production React applications with Cursor, Claude Code, and Codex. They cover typed components generated from designs, data tables with sorting and pagination, Zustand and React Query state management, performance audits, custom hook libraries, error boundaries, Server and Client Component splits in React 19, accessible modals, optimistic UI, form validation, and migrating from Create React App to Vite.

Your designer just handed you a Figma file with 30 screens, your tech lead wants TypeScript everywhere, and the deadline is next Friday. These recipes turn that pressure into shipped features. Each one is a copy-paste prompt that produces production-quality React code — not a tutorial component that falls apart when you add real data.

  • Prompts for generating typed React components from designs or requirements
  • State management recipes for Zustand, React Query, and context patterns
  • Performance optimization prompts that find and fix real bottlenecks
  • Testing recipes that produce meaningful coverage, not checkbox tests

Recipe 1: Generate a Typed Component from a Figma Design

Section titled “Recipe 1: Generate a Typed Component from a Figma Design”

Scenario: You have a Figma design for a pricing card and need a pixel-accurate React component with TypeScript props and Tailwind styling.

Enable the desktop MCP server in Figma (Dev Mode inspect panel > Enable desktop MCP server), then add http://127.0.0.1:3845/mcp in Cursor Settings > MCP. Select the component in Figma, then open Agent mode.

Expected output: A .tsx component file with a typed props interface, Tailwind classes matching the design, responsive variants, and a companion .stories.tsx file with at least three variants (default, loading, error).


Recipe 2: Build a Data Table with Sorting, Filtering, and Pagination

Section titled “Recipe 2: Build a Data Table with Sorting, Filtering, and Pagination”

Scenario: You need a reusable data table component for an admin dashboard that handles 10,000+ rows without choking.

Expected output: Three files — DataTable.tsx with the generic component, data-table.types.ts with shared types, and DataTableExample.tsx demonstrating usage with a User type.


Recipe 3: Convert a Class Component to Hooks

Section titled “Recipe 3: Convert a Class Component to Hooks”

Scenario: You inherited a 400-line class component with componentDidMount, componentDidUpdate, and shouldComponentUpdate. It needs to become a functional component without changing any behavior.

Expected output: A functional UserDashboard component, a useUserDashboard.ts custom hook, and all existing tests still passing.


Recipe 4: Set Up Zustand with TypeScript and Persist Middleware

Section titled “Recipe 4: Set Up Zustand with TypeScript and Persist Middleware”

Scenario: You need global client state for user preferences, theme, and sidebar collapse state. It should survive page refreshes.

Expected output: The store file, a selectors.ts file with typed hooks, and a __tests__/app-store.test.ts file testing all actions and persistence.


Recipe 5: Integrate React Query for Server State

Section titled “Recipe 5: Integrate React Query for Server State”

Scenario: Your app makes 15 different API calls and you are managing loading/error states with useState everywhere. Time to centralize with React Query.

Expected output: Query client config, 5 custom hooks, a provider wrapper, a test utility, and at least one test per hook.


Scenario: Your React app takes 4 seconds to render the product listing page. The React DevTools Profiler shows 200+ unnecessary re-renders.

Open the components directory, select all files, then use Agent mode with the prompt below.

Expected output: Modified component files with targeted optimizations, each documented with a comment explaining the performance rationale.


Recipe 7: Generate Comprehensive Component Tests

Section titled “Recipe 7: Generate Comprehensive Component Tests”

Scenario: You have a CheckoutForm component with validation, API calls, and conditional rendering. It has zero tests.

Expected output: A CheckoutForm.test.tsx file with 8+ test cases, proper mocking setup, and accessibility assertions.


Scenario: Your team keeps reimplementing the same patterns — debouncing, local storage sync, media queries, intersection observer. You need a shared hooks library.

Expected output: Seven hook files, seven test files, and a barrel export index.ts.


Recipe 9: Implement Error Boundaries with Recovery

Section titled “Recipe 9: Implement Error Boundaries with Recovery”

Scenario: When a component in your dashboard crashes, the entire page goes white. You need granular error boundaries that let users retry.

Expected output: Three component files, one hook file, one test file covering error catching and recovery.


Recipe 10: Server Component and Client Component Split (React 19)

Section titled “Recipe 10: Server Component and Client Component Split (React 19)”

Scenario: You are migrating a Next.js page to use React Server Components. You need to identify which parts need "use client" and which can stay on the server.

Expected output: Refactored page with clear server/client boundaries, documented with comments explaining each decision.


Recipe 11: Build an Accessible Modal System

Section titled “Recipe 11: Build an Accessible Modal System”

Scenario: Your app has 5 different modal implementations, none of them handle focus trapping or keyboard navigation correctly.

Expected output: Modal component directory with compound components, hook, confirm variant, and accessibility tests.


Recipe 12: Implement Optimistic UI for a Todo App

Section titled “Recipe 12: Implement Optimistic UI for a Todo App”

Scenario: Your todo list feels sluggish because every action waits for the server response before updating the UI.

Expected output: Refactored mutation hooks with optimistic update logic, updated UI components showing sync indicators, and tests verifying optimistic behavior.


Recipe 13: Create a Form Builder with Validation

Section titled “Recipe 13: Create a Form Builder with Validation”

Scenario: Your app has 12 forms and each one handles validation differently. You need a consistent form system.

Expected output: FormField component, Form wrapper, 4 Zod schemas, custom hook, and validation tests.


Recipe 14: Implement Code Splitting with Route-Based Lazy Loading

Section titled “Recipe 14: Implement Code Splitting with Route-Based Lazy Loading”

Scenario: Your bundle is 2.4 MB and the initial load takes 6 seconds on mobile. Most users only visit 2-3 pages per session.

Expected output: Updated router with lazy routes, Suspense wrappers, error boundaries, prefetch utility, and a LazyRoute component.


Recipe 15: Migrate from Create React App to Vite

Section titled “Recipe 15: Migrate from Create React App to Vite”

Scenario: Your CRA build takes 90 seconds and hot reload has a 3-second delay. Time to move to Vite.

Expected output: Updated config files, migrated environment variables, removed CRA dependencies, and a working Vite setup.