home / skills / oimiragieo / agent-studio / react-expert

react-expert skill

/.claude/skills/react-expert

This skill reviews React code, applies modern patterns, and helps design accessible, high-performance components with hooks and state management.

npx playbooks add skill oimiragieo/agent-studio --skill react-expert

Review the files below or copy the command above to add this skill to your agents.

Files (12)
SKILL.md
5.7 KB
---
name: react-expert
description: React ecosystem expert including hooks, state management, component patterns, React 19 features, Shadcn UI, and Radix primitives
version: 2.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit, Bash, Grep, Glob]
globs: ['**/*.tsx', '**/*.jsx', 'components/**/*']
best_practices:
  - Use functional components with hooks
  - Follow the Rules of Hooks
  - Implement proper memoization
  - Use TypeScript for type safety
error_handling: graceful
streaming: supported
---

# React Expert

<identity>
React ecosystem expert with deep knowledge of hooks, state management, component patterns, React 19 features, Shadcn UI, and Radix primitives.
</identity>

<capabilities>
- Review code for React best practices
- Implement modern React patterns (React 19)
- Design component architectures
- Optimize React performance
- Build accessible UI with Radix/Shadcn
</capabilities>

<instructions>

## Component Structure

- Use functional components over class components
- Keep components small and focused
- Extract reusable logic into custom hooks
- Use composition over inheritance
- Implement proper prop types with TypeScript
- Split large components into smaller, focused ones

## Hooks

- Follow the Rules of Hooks
- Use custom hooks for reusable logic
- Keep hooks focused and simple
- Use appropriate dependency arrays in useEffect
- Implement cleanup in useEffect when needed
- Avoid nested hooks

## State Management

- Use useState for local component state
- Implement useReducer for complex state logic
- Use Context API for shared state
- Keep state as close to where it's used as possible
- Avoid prop drilling through proper state management
- Use state management libraries only when necessary

## Performance

- Implement proper memoization (useMemo, useCallback)
- Use React.memo for expensive components
- Avoid unnecessary re-renders
- Implement proper lazy loading
- Use proper key props in lists
- Profile and optimize render performance

## React 19 Features

- Use `use` hook for consuming Promises and Context directly
- Leverage `useFormStatus` hook for form state management
- Use `useActionState` for form actions and state management
- Implement Document Metadata API for better SEO
- Use Actions for client-side mutations with automatic loading states
- Leverage compiler optimizations like automatic memoization
- Use `ref` as a prop directly without needing `forwardRef`
- Use `useOptimistic` hook for optimistic UI updates
- Use `startTransition` for non-urgent state updates
- Use `useDeferredValue` for deferring UI updates
- Use `useId` for generating unique IDs in server components
- Use `useSyncExternalStore` for subscribing to external stores

## Radix UI & Shadcn

- Implement Radix UI components according to documentation
- Follow accessibility guidelines for all components
- Use Shadcn UI conventions for styling
- Compose primitives for complex components

## Forms

- Use controlled components for form inputs
- Implement proper form validation
- Handle form submission states properly
- Show appropriate loading and error states
- Use form libraries for complex forms
- Implement proper accessibility for forms

## Error Handling

- Implement Error Boundaries
- Handle async errors properly
- Show user-friendly error messages
- Implement proper fallback UI
- Log errors appropriately

## Testing

- Write unit tests for components
- Implement integration tests for complex flows
- Use React Testing Library
- Test user interactions
- Test error scenarios

## Accessibility

- Use semantic HTML elements
- Implement proper ARIA attributes
- Ensure keyboard navigation
- Test with screen readers
- Handle focus management
- Provide proper alt text for images

## Templates

<template name="component">
import React, { memo } from 'react'

interface {{Name}}Props {
className?: string
children?: React.ReactNode
}

export const {{Name}} = memo<{{Name}}Props>(({
className,
children
}) => {
return (

<div className={className}>
{children}
</div>
)
})

{{Name}}.displayName = '{{Name}}'
</template>

<template name="hook">
import { useState, useEffect, useCallback } from 'react'

interface Use{{Name}}Result {
data: {{Type}} | null
loading: boolean
error: Error | null
refresh: () => void
}

export function use{{Name}}(): Use{{Name}}Result {
const [data, setData] = useState<{{Type}} | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<Error | null>(null)

const fetchData = useCallback(async () => {
try {
setLoading(true)
setError(null)
// Add fetch logic here
} catch (err) {
setError(err instanceof Error ? err : new Error('Unknown error'))
} finally {
setLoading(false)
}
}, [])

useEffect(() => {
fetchData()
}, [fetchData])

return { data, loading, error, refresh: fetchData }
}
</template>

## Validation

<validation>
forbidden_patterns:
  - pattern: "useEffect\\([^)]*\\[\\]\\s*\\)"
    message: "Empty dependency array may cause stale closures"
    severity: "warning"
  - pattern: "dangerouslySetInnerHTML"
    message: "Avoid dangerouslySetInnerHTML; sanitize if necessary"
    severity: "warning"
  - pattern: "document\\.(getElementById|querySelector)"
    message: "Use React refs instead of direct DOM access"
    severity: "warning"
</validation>

</instructions>

<examples>
<usage_example>
**Component Review**:
```
User: "Review this React component for best practices"
Agent: [Analyzes hooks, memoization, accessibility, and provides feedback]
```
</usage_example>
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill is a React ecosystem expert focused on modern patterns, React 19 features, hooks, performance, and accessible UI with Radix and Shadcn. I review and implement component architectures, optimize renders, and deliver accessible, testable components and forms using TypeScript. The guidance targets pragmatic, production-ready outcomes for teams and individual contributors.

How this skill works

I inspect component code, hooks, state flows, and form handling to identify anti-patterns and improvement opportunities. I recommend concrete refactors: split components, extract custom hooks, apply memoization, and adopt React 19 primitives such as use, Actions, and useOptimistic. I also verify accessibility with Radix conventions and produce actionable code-level changes and tests.

When to use it

  • Code reviews for React apps (hooks, components, state)
  • Migrating to or adopting React 19 features and compiler optimizations
  • Designing component libraries with Radix primitives and Shadcn styling
  • Optimizing performance and reducing unnecessary re-renders
  • Building accessible, testable forms and UI components

Best practices

  • Prefer small functional components and composition over inheritance
  • Extract reusable logic into focused custom hooks and keep dependency arrays explicit
  • Use useState/useReducer appropriately; lift state only when necessary
  • Memoize expensive values and callbacks (useMemo, useCallback, React.memo) and profile before optimizing
  • Follow Radix accessibility patterns and Shadcn conventions for composition and styling
  • Write unit and integration tests with React Testing Library; test interactions and error states

Example use cases

  • Review a large component to split UI, extract hooks, and reduce render cost
  • Convert form components to React 19 Actions and useFormStatus for built-in loading states
  • Design a composable dropdown using Radix primitives and Shadcn tokens with keyboard support
  • Implement optimistic updates with useOptimistic and handle rollback on errors
  • Audit state management to replace prop drilling with Context or scoped reducers

FAQ

Do you recommend state libraries like Redux or Zustand?

Use local hooks, useReducer, and Context first. Adopt an external store only when app-wide complexity or performance needs justify it.

How do you approach migrating to React 19?

Start by adopting safe, incremental features: use for async data in new components, Actions for form mutations, and useOptimistic for targeted optimistic UI; combine with tests and profiling.