react-component-pro

Build reusable, accessible, performant React components with hooks, composition patterns, and modern best practices. Use when building React UIs, creating component libraries, or optimizing React performance.

React Component Pro

You build production-grade React components that are reusable, accessible, and performant.

Component Principles

  1. Composition over inheritance — Build with small, composable pieces
  2. Single responsibility — One component, one purpose
  3. Props down, events up — Data flows down, actions flow up
  4. Controlled > Uncontrolled — Parent controls state when possible
  5. Accessibility first — ARIA attributes, keyboard navigation, semantic HTML

Component Patterns

Compound Components

<Select value={value} onChange={onChange}>
  <Select.Trigger>Choose option</Select.Trigger>
  <Select.Content>
    <Select.Item value="a">Option A</Select.Item>
    <Select.Item value="b">Option B</Select.Item>
  </Select.Content>
</Select>

Custom Hooks

function useDebounce<T>(value: T, delay: number): T {
  const [debouncedValue, setDebouncedValue] = useState(value)
  
  useEffect(() => {
    const timer = setTimeout(() => setDebouncedValue(value), delay)
    return () => clearTimeout(timer)
  }, [value, delay])
  
  return debouncedValue
}

Render Props / Children as Function

<DataFetcher url="/api/users">
  {({ data, loading, error }) => (
    loading ? <Spinner /> : <UserList users={data} />
  )}
</DataFetcher>

Performance Optimization

ProblemSolution
Unnecessary re-rendersReact.memo, useMemo, useCallback
Heavy computationsuseMemo with proper deps
Large listsVirtualization (react-window)
Code splittingReact.lazy + Suspense
State updates causing full re-renderLocal state, context splitting

TypeScript Patterns for Components

// Props with children
interface CardProps {
  title: string
  variant?: 'default' | 'outlined' | 'elevated'
  children: React.ReactNode
}

// Forwarded ref
const Input = React.forwardRef<HTMLInputElement, InputProps>(
  ({ label, ...props }, ref) => (
    <div>
      <label>{label}</label>
      <input ref={ref} {...props} />
    </div>
  )
)

// Generic component
interface ListProps<T> {
  items: T[]
  renderItem: (item: T) => React.ReactNode
}

Accessibility Checklist

  • Semantic HTML (button not div onClick)
  • ARIA labels for interactive elements
  • Keyboard navigation (Tab, Enter, Escape)
  • Focus management (modals, dropdowns)
  • Color contrast ≥ 4.5:1
  • Screen reader tested