π¨ Component Patterns
Modern React components use:
React.FC for type safetyReact.lazy() for code splittingSuspenseLoader for loading states- Named const + default export pattern
Key Concepts:
- Lazy load heavy components (DataGrid, charts, editors)
- Always wrap lazy components in Suspense
- Use SuspenseLoader component (with fade animation)
- Component structure: Props β Hooks β Handlers β Render β Export
[π Complete Guide: resources/component-patterns.md](resources/component-patterns.md)
---
π Data Fetching
PRIMARY PATTERN: useSuspenseQuery
- Use with Suspense boundaries
- Cache-first strategy (check grid cache before API)
- Replaces
isLoading checks - Type-safe with generics
API Service Layer:
- Create
features/{feature}/api/{feature}Api.ts - Use
apiClient axios instance - Centralized methods per feature
- Route format:
/form/route (NOT /api/form/route)
[π Complete Guide: resources/data-fetching.md](resources/data-fetching.md)
---
π File Organization
features/ vs components/:
features/: Domain-specific (posts, comments, auth)components/: Truly reusable (SuspenseLoader, CustomAppBar)
Feature Subdirectories:
```
features/
my-feature/
api/ # API service layer
components/ # Feature components
hooks/ # Custom hooks
helpers/ # Utility functions
types/ # TypeScript types
```
[π Complete Guide: resources/file-organization.md](resources/file-organization.md)
---
π¨ Styling
Inline vs Separate:
- <100 lines: Inline
const styles: Record> - >100 lines: Separate
.styles.ts file
Primary Method:
- Use
sx prop for MUI components - Type-safe with
SxProps - Theme access:
(theme) => theme.palette.primary.main
MUI v7 Grid:
```typescript
// β
v7 syntax
// β Old syntax
```
[π Complete Guide: resources/styling-guide.md](resources/styling-guide.md)
---
π£οΈ Routing
TanStack Router - Folder-Based:
- Directory:
routes/my-route/index.tsx - Lazy load components
- Use
createFileRoute - Breadcrumb data in loader
Example:
```typescript
import { createFileRoute } from '@tanstack/react-router';
import { lazy } from 'react';
const MyPage = lazy(() => import('@/features/my-feature/components/MyPage'));
export const Route = createFileRoute('/my-route/')({
component: MyPage,
loader: () => ({ crumb: 'My Route' }),
});
```
[π Complete Guide: resources/routing-guide.md](resources/routing-guide.md)
---
β³ Loading & Error States
CRITICAL RULE: No Early Returns
```typescript
// β NEVER - Causes layout shift
if (isLoading) {
return ;
}
// β
ALWAYS - Consistent layout
```
Why: Prevents Cumulative Layout Shift (CLS), better UX
Error Handling:
- Use
useMuiSnackbar for user feedback - NEVER
react-toastify - TanStack Query
onError callbacks
[π Complete Guide: resources/loading-and-error-states.md](resources/loading-and-error-states.md)
---
β‘ Performance
Optimization Patterns:
useMemo: Expensive computations (filter, sort, map)useCallback: Event handlers passed to childrenReact.memo: Expensive components- Debounced search (300-500ms)
- Memory leak prevention (cleanup in useEffect)
[π Complete Guide: resources/performance.md](resources/performance.md)
---
π TypeScript
Standards:
- Strict mode, no
any type - Explicit return types on functions
- Type imports:
import type { User } from '~types/user' - Component prop interfaces with JSDoc
[π Complete Guide: resources/typescript-standards.md](resources/typescript-standards.md)
---
π§ Common Patterns
Covered Topics:
- React Hook Form with Zod validation
- DataGrid wrapper contracts
- Dialog component standards
useAuth hook for current user- Mutation patterns with cache invalidation
[π Complete Guide: resources/common-patterns.md](resources/common-patterns.md)
---
π Complete Examples
Full working examples:
- Modern component with all patterns
- Complete feature structure
- API service layer
- Route with lazy loading
- Suspense + useSuspenseQuery
- Form with validation
[π Complete Guide: resources/complete-examples.md](resources/complete-examples.md)
---