devs%3Areact-core by aaronbassett/agent-foundry
npx skills add https://github.com/aaronbassett/agent-foundry --skill devs:react-core遵循现代最佳实践,构建可扩展、高性能且安全的 React 应用程序的全面指南。
使用 Vite 初始化:
pnpm create vite my-app --template react-ts
cd my-app
pnpm install
使用配置模板:
安装核心依赖:
# 路由
pnpm add react-router-dom
# 数据获取
pnpm add @tanstack/react-query
# 表单
pnpm add react-hook-form @hookform/resolvers zod
# 状态管理(如果需要)
pnpm add zustand
查看 获取完整布局
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
解决性能问题:
设置状态管理:
实现身份验证:
按功能而非技术类型组织代码:
src/
├── app/ # 应用级路由
├── features/ # 功能模块(自包含)
│ ├── authentication/
│ ├── users/
│ └── dashboard/
├── components/ # 共享组件
├── hooks/ # 共享钩子
├── lib/ # 第三方库设置
└── utils/ # 共享工具函数
核心原则:
查看 project-structure.md 获取完整指南,包括:
为每个用例选择合适的状态解决方案:
| 状态类型 | 工具 | 示例 |
|---|---|---|
| 组件状态 | useState, useReducer | 表单输入、开关 |
| 应用状态 | Context, Zustand, Jotai | 主题、认证状态 |
| 服务器缓存 | React Query, SWR | API 数据 |
| 表单状态 | React Hook Form | 表单值、验证 |
| URL 状态 | React Router | 过滤器、分页 |
决策框架:
查看 state-management.md 获取完整模式,包括:
代码分割 - 按需加载代码
const Dashboard = lazy(() => import('./routes/Dashboard'));
列表虚拟化 - 仅渲染可见项
import { useVirtualizer } from '@tanstack/react-virtual';
图片优化 - 懒加载并使用现代格式
<img src="/image.jpg" loading="lazy" />
打包优化 - 分析并减少打包体积
npx vite-bundle-visualizer
React 19 的编译器会自动进行记忆化 - 使用编译器时,可以移除手动的 React.memo、useMemo、useCallback。
查看 performance.md 获取完整指南,包括:
构建可维护且类型安全的 API 调用:
// features/users/api/get-user.ts
import { z } from 'zod';
import { useQuery } from '@tanstack/react-query';
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
});
export type User = z.infer<typeof userSchema>;
export async function getUser(userId: string): Promise<User> {
const response = await apiClient.get(`/users/${userId}`);
return userSchema.parse(response.data);
}
export function useUser(userId: string) {
return useQuery({
queryKey: ['users', userId],
queryFn: () => getUser(userId),
});
}
查看 api-layer.md 获取完整模式,包括:
遵循测试金字塔:
/\
/E2E\ ← 少量
/------\
/Integr.\ ← 适量
/----------\
/ Unit \ ← 大量
工具:
示例:
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
test('button calls onClick when clicked', async () => {
const handleClick = vi.fn();
const user = userEvent.setup();
render(<Button onClick={handleClick}>Click me</Button>);
await user.click(screen.getByRole('button'));
expect(handleClick).toHaveBeenCalledTimes(1);
});
查看 testing.md 获取完整指南,包括:
示例:
// ✅ 安全的令牌存储
// 服务器设置 HttpOnly cookie
res.cookie('auth_token', token, {
httpOnly: true,
secure: true,
sameSite: 'strict',
});
// ✅ 对用户内容进行消毒
import DOMPurify from 'dompurify';
const sanitized = DOMPurify.sanitize(userContent);
查看 security.md 获取完整指南,包括:
示例:
'use client';
import { useActionState } from 'react';
async function createUserAction(prevState, formData) {
const user = await api.createUser(formData);
return { success: true, user };
}
export function CreateUserForm() {
const [state, formAction, isPending] = useActionState(createUserAction, null);
return (
<form action={formAction}>
<input name="email" required />
<button disabled={isPending}>
{isPending ? '创建中...' : '创建'}
</button>
</form>
);
}
查看 react-19-best-practices.md 获取完整指南。
优化的构建设置,包含代码分割、压缩和摇树优化。
查看 build-and-bundling.md 获取:
查看 ecosystem-tools.md 获取推荐的包:
避免这些常见错误:
查看 common-pitfalls.md 获取示例和解决方案。
正确地为 React 组件添加类型:
type ButtonProps = {
children: React.ReactNode;
variant?: 'primary' | 'secondary';
onClick?: () => void;
};
export function Button({ children, variant = 'primary', onClick }: ButtonProps) {
return <button className={variant} onClick={onClick}>{children}</button>;
}
查看 typescript-react.md 获取完整模式,包括:
架构与组织:
性能与优化:
API 与数据:
测试与质量:
React 19 与现代特性:
工具与生态系统:
故障排除:
用于快速项目设置的预配置文件:
构建快速、安全且可维护的 React 应用程序。
每周安装数
1
仓库
GitHub Stars
1
首次出现
1 天前
安装于
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
Comprehensive guidance for building scalable, performant, and secure React applications with modern best practices.
Initialize with Vite:
pnpm create vite my-app --template react-ts
cd my-app
pnpm install
Use configuration templates:
Install essential dependencies:
# Routing
pnpm add react-router-dom
# Data fetching
pnpm add @tanstack/react-query
# Forms
pnpm add react-hook-form @hookform/resolvers zod
# State management (if needed)
pnpm add zustand
Organize by feature: See project-structure.md for complete layouts
Resolving Performance Issues:
Setting Up State Management:
Implementing Authentication:
Organize code by feature, not by technical type:
src/
├── app/ # App-level routing
├── features/ # Feature modules (self-contained)
│ ├── authentication/
│ ├── users/
│ └── dashboard/
├── components/ # Shared components
├── hooks/ # Shared hooks
├── lib/ # Third-party setup
└── utils/ # Shared utilities
Key principles:
See project-structure.md for complete guide including:
Choose the right state solution for each use case:
| State Type | Tool | Example |
|---|---|---|
| Component | useState, useReducer | Form inputs, toggles |
| Application | Context, Zustand, Jotai | Theme, auth status |
| Server Cache | React Query, SWR | API data |
| Form | React Hook Form | Form values, validation |
| URL | React Router | Filters, pagination |
Decision framework:
See state-management.md for complete patterns including:
Code Splitting - Load code on demand
const Dashboard = lazy(() => import('./routes/Dashboard'));
List Virtualization - Render only visible items
import { useVirtualizer } from '@tanstack/react-virtual';
Image Optimization - Lazy load and use modern formats
<img src="/image.jpg" loading="lazy" />
Bundle Optimization - Analyze and reduce bundle size
npx vite-bundle-visualizer
React 19's compiler automatically memoizes - remove manual React.memo, useMemo, useCallback when using the compiler.
See performance.md for complete guide including:
Structure API calls for maintainability and type safety:
// features/users/api/get-user.ts
import { z } from 'zod';
import { useQuery } from '@tanstack/react-query';
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
});
export type User = z.infer<typeof userSchema>;
export async function getUser(userId: string): Promise<User> {
const response = await apiClient.get(`/users/${userId}`);
return userSchema.parse(response.data);
}
export function useUser(userId: string) {
return useQuery({
queryKey: ['users', userId],
queryFn: () => getUser(userId),
});
}
See api-layer.md for complete patterns including:
Follow the testing pyramid:
/\
/E2E\ ← Few
/------\
/Integr.\ ← Some
/----------\
/ Unit \ ← Many
Tools:
Example:
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
test('button calls onClick when clicked', async () => {
const handleClick = vi.fn();
const user = userEvent.setup();
render(<Button onClick={handleClick}>Click me</Button>);
await user.click(screen.getByRole('button'));
expect(handleClick).toHaveBeenCalledTimes(1);
});
See testing.md for complete guide including:
Example:
// ✅ Secure token storage
// Server sets HttpOnly cookie
res.cookie('auth_token', token, {
httpOnly: true,
secure: true,
sameSite: 'strict',
});
// ✅ Sanitize user content
import DOMPurify from 'dompurify';
const sanitized = DOMPurify.sanitize(userContent);
See security.md for complete guide including:
Example:
'use client';
import { useActionState } from 'react';
async function createUserAction(prevState, formData) {
const user = await api.createUser(formData);
return { success: true, user };
}
export function CreateUserForm() {
const [state, formAction, isPending] = useActionState(createUserAction, null);
return (
<form action={formAction}>
<input name="email" required />
<button disabled={isPending}>
{isPending ? 'Creating...' : 'Create'}
</button>
</form>
);
}
See react-19-best-practices.md for complete guide.
Optimized build setup with code splitting, minification, and tree shaking.
See build-and-bundling.md for:
See ecosystem-tools.md for recommended packages:
Avoid these frequent mistakes:
See common-pitfalls.md for examples and solutions.
Type your React components properly:
type ButtonProps = {
children: React.ReactNode;
variant?: 'primary' | 'secondary';
onClick?: () => void;
};
export function Button({ children, variant = 'primary', onClick }: ButtonProps) {
return <button className={variant} onClick={onClick}>{children}</button>;
}
See typescript-react.md for complete patterns including:
Architecture & Organization:
Performance & Optimization:
API & Data:
Testing & Quality:
React 19 & Modern Features:
Tools & Ecosystem:
Troubleshooting:
Pre-configured files for quick project setup:
Build React applications that are fast, secure, and maintainable.
Weekly Installs
1
Repository
GitHub Stars
1
First Seen
1 day ago
Installed on
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1
Flutter应用架构设计指南:分层结构、数据层实现与最佳实践
4,000 周安装