Skip to main content

Component Architecture

Zarna components follow consistent patterns based on shadcn/ui conventions and React best practices.

Basic Component Structure

shadcn/ui Pattern

All shadcn components follow this structure:

Component Patterns

1. Composable Components

Break components into smaller, reusable pieces:

2. Polymorphic Components

Use asChild for component flexibility:

3. Forwarding Refs

Always forward refs for flexibility:

4. Controlled vs Uncontrolled

Controlled (recommended for forms):
Uncontrolled (for simple cases):

Creating Custom Components

Example: Custom Card Component

Common Component Patterns

Loading States

Error States

Empty States

Form Components

Using React Hook Form + Zod

Server vs Client Components

When to Use “use client”

Only add "use client" when you need:
  • React Hooks: useState, useEffect, useContext, etc.
  • Browser APIs: window, document, localStorage, etc.
  • Event Handlers: onClick, onChange, onSubmit, etc.
  • Third-party libraries: That use hooks or browser APIs

Performance Patterns

Lazy Loading

Memoization

React.memo

Accessibility Patterns

Keyboard Navigation

ARIA Labels

Focus Management

Best Practices

Keep components focused and readable by extracting complex logic

Component Organization Template

Next Steps

Best Practices

Learn coding standards and patterns

Theme System

Understand styling and theming

Project Structure

See where components live

Tech Stack

Explore component libraries