UI Engineering

Claude 3.5 Sonnet:
Flawless React Components.

A practical frontend engineering guide to prompting Claude for clean, typed, accessible, testable React components that fit your design system.

By RankMaster Tech//14 min read
Claude 3.5 Sonnet Best Practices: Writing Flawless React Components

Claude 3.5 Sonnet became one of the most important AI coding models for frontend teams because it was fast, readable, strong at UI reasoning, and paired well with iterative workflows like Artifacts. But the difference between a useful AI component and a production-ready React component is not the model alone. It is the prompt, the design-system context, the review process, and the quality gates around the generated code.

Anthropic introduced Claude 3.5 Sonnet in June 2024 and also introduced Artifacts on Claude.ai, a workspace where generated content such as code snippets, documents, and website designs can appear in a dedicated window beside the conversation. Anthropic Claude 3.5 Sonnet announcement Anthropic later described Artifacts as a way to see, edit, and build with Claude in a side-by-side workspace. Anthropic Projects and Artifacts announcement

This guide focuses on Claude 3.5 Sonnet because many teams still search for its React coding workflows. However, the same frontend prompting principles apply to newer Claude Sonnet models as well. In fact, Anthropic’s current model documentation should always be checked before choosing a production coding workflow, because model availability, pricing, and coding capabilities change over time. Claude model overview

The Real Goal: Not “Generate a Component,” But “Generate a Maintainable Component”

Most developers use Claude too vaguely. They ask for “a dashboard card” or “a pricing table” and then wonder why the result does not fit their app. A React component is not only a visual block. It is a contract between design, data, accessibility, state, and future maintenance.

React’s own documentation explains that components let developers split UI into independent, reusable pieces, and props let parent components pass information to child components. React components and props documentation React passing props documentation That means your prompt should define the component boundary, the props, and the behavior before Claude writes code.

A maintainable AI-generated React component should have:

  • A clear purpose and single responsibility.
  • Typed props and predictable data shape.
  • No hidden business logic unless requested.
  • Accessible labels, keyboard behavior, and semantic HTML.
  • Responsive layout rules.
  • Loading, empty, error, and disabled states.
  • Styling that follows your design system.
  • Tests or Storybook states for important variations.

Best Practice 1: Give Claude a Component Contract

A component contract tells Claude what the component accepts, what it renders, and what it must not do. Without this, the model may invent props, hardcode data, or mix UI and business logic.

Use this prompt structure:

Create a React TypeScript component named CustomerStatusCard.

Requirements:
- Use strict TypeScript.
- Props:
  - customerName: string
  - planName: string
  - status: "active" | "trial" | "past_due" | "cancelled"
  - renewalDate?: string
  - onManageBilling?: () => void
- Use Tailwind CSS utility classes.
- Do not fetch data inside the component.
- Do not import UI libraries unless I provide them.
- Include loading, empty, and disabled states if needed.
- Use semantic HTML and accessible button labels.
- Return only the component code.

This is far better than “make a customer status card.” Claude now has a shape, a boundary, and constraints.

Best Practice 2: Ask for TypeScript First

TypeScript is one of the easiest ways to make Claude-generated React safer. The React TypeScript guide explains that TypeScript can help with React code, and the TypeScript documentation provides the core language reference for types, interfaces, generics, narrowing, and object types. React TypeScript guide TypeScript documentation

When prompting Claude, ask for:

  • Explicit prop interfaces.
  • Discriminated unions for variant components.
  • Typed event handlers.
  • No any unless there is a clear reason.
  • Readable type names.
  • Separate domain types from UI-only types.

A good prompt might say: “Use strict TypeScript. Do not use any. If a field can be missing, model it explicitly. Use a discriminated union if the component has mutually exclusive variants.”

Best Practice 3: Modularize Before Styling

Claude is good at generating complete UI sections, but large generated files become hard to review. Instead of asking for an entire page, ask for one component at a time.

A better workflow:

  1. Ask Claude to design the component hierarchy.
  2. Review the hierarchy before code generation.
  3. Generate the smallest reusable component first.
  4. Add variants and states.
  5. Generate tests or Storybook stories.
  6. Then compose the page.

For example, a billing dashboard should not be generated as one 700-line component. Break it into PlanSummaryCard, UsageMeter, InvoiceTable, PaymentMethodPanel, and UpgradePrompt. Claude will produce cleaner output when each component has one responsibility.

Best Practice 4: Provide Design-System Rules

Claude cannot know your design system unless you describe it. If you use Tailwind, tell Claude the spacing scale, color tokens, rounded corners, shadows, font sizes, and responsive rules you prefer.

Tailwind’s official documentation describes utility classes as single-purpose presentational classes used directly in markup, and Tailwind responsive design lets utility classes apply conditionally at different breakpoints. Tailwind utility classes documentation Tailwind responsive design documentation

A strong Tailwind prompt includes:

  • Use existing tokens instead of arbitrary values.
  • Prefer consistent spacing such as p-4, p-6, gap-4, and gap-6.
  • Use responsive classes for mobile-first layouts.
  • Do not add inline styles unless absolutely necessary.
  • Use accessible contrast and visible focus states.
  • Keep class strings readable and grouped logically.

If your project uses shadcn/ui, Radix, Chakra, MUI, or a custom component library, include the import patterns and examples in the prompt. Do not let Claude invent unavailable components.

Best Practice 5: Prompt for Accessibility Explicitly

Accessible UI rarely happens by accident. React supports building accessible websites using standard HTML techniques, and accessibility helps assistive technologies interpret pages correctly. React accessibility documentation

Ask Claude for:

  • Semantic HTML first.
  • Buttons for actions and links for navigation.
  • Labels for inputs.
  • Keyboard support for interactive components.
  • Visible focus states.
  • ARIA only when semantic HTML is not enough.
  • Meaningful alt text for informative images.
  • Error messages connected to form fields.

A practical prompt line is: “Use accessible HTML. Do not add ARIA unless necessary. Include keyboard behavior and visible focus states for interactive elements.”

Best Practice 6: Use Artifacts for UI Iteration, Not Final Approval

Artifacts are valuable because they let you iterate visually with Claude. They are excellent for exploring layouts, comparing states, and refining component behavior before moving code into your repository.

But a preview is not a production review. Before code ships, move it through your normal workflow:

  • Run TypeScript and lint checks.
  • Review imports and dependencies.
  • Check accessibility manually and with tools.
  • Test responsive behavior on real screen sizes.
  • Add unit or interaction tests.
  • Verify design-system consistency.
  • Open a pull request for human review.

Artifacts can accelerate ideation, but the repository remains the source of truth.

Best Practice 7: Ask for Edge States

Claude often generates the happy path unless you ask for edge states. Production components need more than the default state.

For every component, ask Claude to include:

  • Loading state.
  • Empty state.
  • Error state.
  • Disabled state.
  • Long text overflow.
  • Mobile layout.
  • High-data and low-data examples.
  • Permission-limited state if relevant.

This is especially important for SaaS dashboards, tables, billing screens, admin panels, and forms where real-world data is messy.

Best Practice 8: Add Storybook Stories

Storybook is a frontend workshop for building UI components and pages in isolation. Its documentation says Storybook helps teams develop and share hard-to-reach states and edge cases without running the whole app. Storybook documentation

Ask Claude to create Storybook stories for:

  • Default state.
  • Loading state.
  • Error state.
  • Empty state.
  • Long content state.
  • Mobile or narrow-width layout.
  • Dark mode if your app supports it.
  • Role-based variants.

A good prompt: “After the component, create a Storybook file with Default, Loading, Empty, Error, and LongContent stories. Use realistic mock props.”

Best Practice 9: Generate Tests That Match User Behavior

React Testing Library encourages tests that resemble how users interact with applications, which can improve confidence that components work for real users. React Testing Library introduction Testing Library also recommends queries that reflect the experience of visual users and assistive technology users. Testing Library queries guide

Ask Claude for tests that verify:

  • The component renders meaningful text.
  • Buttons and inputs are accessible by role or label.
  • Callbacks fire when users interact.
  • Error messages appear when expected.
  • Disabled controls cannot be clicked.
  • Loading state is announced or visible.
  • Keyboard interactions work for menus, dialogs, and comboboxes.

Avoid tests that only check implementation details. If a test knows too much about internal state, it becomes fragile when the component is refactored.

Best Practice 10: Tell Claude What Not to Do

Negative constraints are useful. Claude may otherwise add dependencies, fetch data inside UI components, invent icons, or introduce patterns that conflict with your codebase.

Add constraints like:

Do not:
- Add new dependencies.
- Fetch data inside this component.
- Use any.
- Use inline styles.
- Use hardcoded demo data inside the component.
- Invent design-system components.
- Use ARIA where semantic HTML works.
- Create a giant page component.
- Mix API logic with presentational UI.

These constraints reduce cleanup time and make the output easier to merge.

A Production Prompt Template for Claude 3.5 Sonnet

You are a senior frontend engineer. Generate a production-ready React component.

Context:
- Stack: React + TypeScript + Tailwind CSS.
- Use strict TypeScript.
- Existing design style: clean SaaS UI, rounded-2xl cards, subtle borders, accessible focus states.
- Do not add new dependencies.
- Do not fetch data in the component.

Component:
- Name:
- Purpose:
- Props:
- States:
- User interactions:
- Accessibility requirements:
- Responsive behavior:
- Empty/loading/error states:
- Test expectations:

Output:
1. Component code.
2. Type definitions if separate.
3. React Testing Library tests.
4. Storybook stories.
5. Brief notes on assumptions.

This template works because it gives Claude the same context a human teammate would need before writing production code.

Common Mistakes When Using Claude for React

Mistake 1: Asking for a full page first

Full-page generation often creates tangled components. Start with a component hierarchy, then generate pieces one by one.

Mistake 2: Not providing project context

Claude cannot follow your design system, folder structure, import aliases, or state-management approach unless you provide them.

Mistake 3: Accepting invented dependencies

AI models may import libraries that are not installed. Tell Claude to use only approved dependencies or your existing component library.

Mistake 4: Skipping accessibility review

A component that looks correct may still fail keyboard, label, focus, or screen-reader expectations.

Mistake 5: Treating AI output as final code

Claude accelerates drafting. It does not replace review, tests, linting, type checking, accessibility checks, and product judgment.

Workflow: From Claude Draft to Production Component

  1. Write a component contract.
  2. Ask Claude for the hierarchy first.
  3. Generate one component at a time.
  4. Iterate visually in Artifacts if useful.
  5. Ask for tests and Storybook stories.
  6. Paste into your repo and run format, lint, typecheck, and tests.
  7. Review accessibility and responsive behavior.
  8. Open a pull request with human review.
  9. Refactor if the generated code does not match project conventions.

This workflow keeps Claude as an accelerator, not an uncontrolled code source.

The Gadzooks Recommendation

Claude 3.5 Sonnet is strongest when you treat it like a senior pair-programming assistant that needs a clear brief. Give it the component purpose, prop contract, design-system rules, accessibility requirements, edge states, and test expectations. Then review the output like you would review code from a human teammate.

For frontend teams, the best AI workflow is not “prompt and paste.” It is “brief, generate, inspect, test, and integrate.” That is how Claude-generated components become reliable SaaS UI instead of disposable demo code.

Gadzooks Solutions helps SaaS teams build React and Next.js frontends with AI-assisted workflows, design systems, component libraries, Storybook documentation, test automation, accessibility reviews, and production-ready frontend architecture.

FAQ: Claude 3.5 Sonnet React Best Practices

Is Claude 3.5 Sonnet still worth learning for React?

Yes, because many Claude React workflows were built around Claude 3.5 Sonnet and its Artifacts experience. However, always check the latest Claude model documentation before choosing a production model, because newer Sonnet models may be stronger for coding.

How do I stop Claude from over-engineering components?

Give Claude a narrow component contract and clear constraints. Tell it not to add dependencies, not to fetch data, not to create global state, and not to build the whole page unless requested.

Should Claude generate tests too?

Yes. Ask Claude for React Testing Library tests that check user-visible behavior, accessibility roles, interactions, error states, and disabled states. Review and adjust the tests before merging.

Can Claude help with Tailwind CSS?

Yes. Claude can generate Tailwind-based layouts effectively when you specify your design tokens, spacing rules, responsive behavior, dark mode expectations, and focus states.

What should I provide Claude from my codebase?

Provide existing component examples, naming conventions, import aliases, design-system tokens, approved dependencies, folder structure, and state-management rules. This helps Claude match your project instead of inventing a new style.

Sources