);
}
export function AppErrorBoundary({ children }: { children: React.ReactNode }) {
return {children};
}
```
### Step 6: Build Validated Forms
```tsx
// src/features/items/CreateItemForm.tsx
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
const itemSchema = z.object({
title: z.string().min(3, 'Title must be at least 3 characters'),
description: z.string().min(10, 'Description must be at least 10 characters'),
priority: z.enum(['low', 'medium', 'high']),
});
type ItemFormData = z.infer;
export function CreateItemForm() {
const { register, handleSubmit, formState: { errors } } = useForm({
resolver: zodResolver(itemSchema),
});
const createItem = useCreateItem();
return (
);
}
```
### Step 7: Verify the Pattern Works
```bash
npm run dev
# Open http://localhost:5173 and test the feature
npm run type-check
# or: npx tsc --noEmit
```
## Resources
- `references/hook-patterns.md` - Custom hook patterns and anti-patterns
- `references/component-checklist.md` - Quality checklist for React components
## Examples
### Example 1: Create a Data Fetching Hook
User asks: "Create a hook to fetch and cache user profiles"
Response approach:
1. Create `useUser(id)` and `useUsers(filters)` hooks using React Query
2. Add `useCreateUser()` mutation with cache invalidation
3. Add toast notifications for success/error states
4. Show usage in a container component
### Example 2: Build a Feature Module
User asks: "Create the orders feature with list, detail, and create form"
Response approach:
1. Create `useOrders()` and `useCreateOrder()` hooks
2. Build `OrderList` presenter and `OrderListContainer`
3. Build `CreateOrderForm` with Zod validation
4. Wrap in `ErrorBoundary`
5. Add route entries and test with `npm run dev`
## Notes
- Prefer composition (children, render props) over configuration (boolean props)
- Never duplicate API data in Zustand -- use React Query for server state
- Keep presenters pure: no hooks, no side effects, just props and JSX
- Always type props with TypeScript interfaces, not `any`
- Use `enabled: !!id` in useQuery to prevent fetching with empty IDs