react
React rules for the project Applies to files matching: **/*.tsx.
When & Why to Use This Skill
This Claude skill establishes a comprehensive set of React and TypeScript coding standards designed for modern web development. It enforces industry best practices such as functional component architecture, strict hook management, and named exports to ensure codebase maintainability. By providing clear guidelines for server/client component separation and secure configuration handling, it helps developers build scalable, high-performance, and secure React applications while minimizing technical debt.
Use Cases
- Automated Code Auditing: Use these rules to automatically review .tsx files, ensuring all components follow the named export pattern and adhere to React hook best practices.
- Standardizing Form Architecture: Implement consistent, type-safe form validation across projects by enforcing the use of React Hook Form, Zod, and shadcn UI primitives.
- Next.js Project Governance: Maintain a clean separation between Client and Server components and prevent sensitive data leaks by enforcing the use of specialized configuration providers.
- Performance Optimization: Prevent unnecessary re-renders and side-effect bugs by guiding developers to use derived state instead of redundant useState and useEffect hooks.
- UI Consistency: Ensure visual and structural consistency by mandating the use of shared utility functions for class merging and promoting component composition over nested JSX.
| name | react |
|---|---|
| description | React rules for the project Applies to files matching: **/*.tsx. |
Components
- Prefer function components: Use React function components with hooks over class components.
- Client vs server: Mark interactive components with
"use client"at the top of the file; keep non-interactive logic in server components or libraries. - No default exports: Use named exports for all components.
Hooks
- Hook ordering: Follow the standard rules of hooks; no conditional or looped hooks.
- Derived state: Prefer deriving values from props/form state instead of duplicating them in
useState. - Effects: Keep
useEffectminimal and side effect focused; avoid using it for basic data derivation.
Forms
- Validation: Use
react-hook-form+ Zod for all non-trivial forms. - UI primitives: Prefer shadcn
Formprimitives (Form,FormField,FormItem,FormLabel,FormControl,FormMessage) for form layout and error handling. - Schema location: Co-locate small form schemas with the component; extract only when reused across modules.
Styling & Layout
- Class merging: Use the shared
cnutility for conditional classes. - Composition: Prefer smaller composed components over deeply nested JSX in a single component.
Configuration Access
- Client components: Always use
useConfig()from@/components/config-providerto access site configuration in client components ("use client"). - Never import
siteConfigdirectly in client components—it derives values from server-only environment variables. TheConfigProviderreceives a serialized version that decouples client code from server secrets.