全栈开发规范百科全书 (React/TS/Node/Supabase)...
Comprehensive guide for modern React development, emphasizing Suspense-based data fetching, lazy loading, proper file organization, and performance optimization.
Creating a component? Follow this checklist:
React.FC<Props> pattern with TypeScriptReact.lazy(() => import())<SuspenseLoader> for loading statesuseSuspenseQuery for data fetchinguseCallbackimport React, { useState, useCallback } from 'react';
import { Box, Paper } from '@mui/material';
import { useSuspenseQuery } from '@tanstack/react-query';
import { featureApi } from '../api/featureApi';
import type { FeatureData } from '~types/feature';
interface MyComponentProps {
id: number;
onAction?: () => void;
}
export const MyComponent: React.FC<MyComponentProps> = ({ id, onAction }) => {
const [state, setState] = useState<string>('');
const { data } = useSuspenseQuery({
queryKey: ['feature', id],
queryFn: () => featureApi.getFeature(id),
});
const handleAction = useCallback(() => {
setState('updated');
onAction?.();
}, [onAction]);
return (
<Box sx={{ p: 2 }}>
<Paper sx={{ p: 3 }}>
{/* Content */}
</Paper>
</Box>
);
};
export default MyComponent;
// Use useSuspenseQuery - No isLoading checks needed!
const { data } = useSuspenseQuery({
queryKey: ['myEntity', id],
queryFn: () => myFeatureApi.getEntity(id),
});
// data is ALWAYS defined (Suspense handles loading)
// Lazy load heavy components
const HeavyComponent = React.lazy(() => import('./HeavyComponent'));
// Wrap in SuspenseLoader
<SuspenseLoader>
<HeavyComponent />
</SuspenseLoader>
any typemakeStyles or styled() (use sx prop)react-toastify (use useMuiSnackbar)useAuth hook)React.FC<Props> with TypeScriptuseSuspenseQuery for data fetchingsx prop for stylingFor domain-specific features with own logic and API:
features/
my-feature/
api/
myFeatureApi.ts
components/
MyFeatureMain.tsx
hooks/
useMyFeature.ts
types/
index.ts
index.ts
For truly reusable UI components:
components/
SuspenseLoader/
CustomAppBar/
ErrorBoundary/
| Topic | File |
|---|---|
| Common patterns | common-patterns.md |
| Component patterns | component-patterns.md |
| Data fetching | data-fetching.md |
| File organization | file-organization.md |
| Loading and errors | loading-and-error-states.md |
| Routing guide | routing-guide.md |
| Styling guide | styling-guide.md |
| TypeScript standards | typescript-standards.md |
Skill Status: COMPLETE ✅ Line Count: < 500 ✅ Progressive Disclosure: 8 resource files ✅