spark-app-template
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpark App Template
Spark 应用模板
Purpose
用途
Spark App Template provides defaults and guidance for building web applications. When a user asks to build a web app, this skill provides the technical foundation and design direction to create functional applications.
Spark 应用模板为Web应用构建提供默认配置和指导。当用户要求构建Web应用时,本工具提供技术基础和设计方向,助力打造功能完备的应用。
When to Use This Skill
何时使用本工具
Activate Spark App Template when the user:
- Wants to build a new web application from scratch
- Asks "what stack should I use?"
- Needs guidance on design, styling, or tech choices
- Wants to start a dashboard, interactive tool, data app, or content site
- Requests help choosing between frameworks, libraries, or approaches
当用户出现以下需求时可启用Spark应用模板:
- 想要从零开始构建全新Web应用
- 询问「我应该使用什么技术栈?」
- 需要设计、样式或技术选型方面的指导
- 想要搭建仪表盘、交互工具、数据应用或内容站点
- 请求协助在框架、库或实现方案之间做选择
Quick Start Workflow
快速开始工作流
CRITICAL: Follow this exact order to avoid configuration errors:
- Create project:
pnpm create vite@latest my-app --template react-ts - Install base dependencies:
pnpm install - Configure TypeScript path aliases (tsconfig.json AND tsconfig.app.json - see Step 1 below)
- Install Tailwind and tooling:
pnpm add -D tailwindcss @tailwindcss/vite @biomejs/biome - Configure vite.config.ts: Add Tailwind plugin and path aliases
- Initialize shadcn: (will now succeed with proper aliases)
pnpm dlx shadcn@latest init - Install required shadcn components: (BEFORE writing components)
pnpm dlx shadcn add button card avatar ... - Install additional packages: TanStack Router, Query, Zustand, etc.
- Write custom components (NOW safe to import from )
@/components/ui/* - Configure routing and state management
- Implement features
Steps 3, 6, and 7 must happen in this exact order to avoid TypeScript errors and failed shadcn installations.
重要提示:严格遵循以下顺序操作,避免配置错误:
- 创建项目:
pnpm create vite@latest my-app --template react-ts - 安装基础依赖:
pnpm install - 配置TypeScript路径别名(需同时修改tsconfig.json和tsconfig.app.json,参考下文步骤1)
- 安装Tailwind和相关工具:
pnpm add -D tailwindcss @tailwindcss/vite @biomejs/biome - 配置vite.config.ts:添加Tailwind插件和路径别名
- 初始化shadcn:(路径别名配置完成后此步骤可顺利执行)
pnpm dlx shadcn@latest init - 安装所需的shadcn组件:(编写自定义组件前完成此步骤)
pnpm dlx shadcn add button card avatar ... - 安装额外依赖包:TanStack Router、Query、Zustand等
- 编写自定义组件(此时可安全从导入组件)
@/components/ui/* - 配置路由和状态管理
- 实现业务功能
步骤3、6、7必须严格按此顺序执行,避免出现TypeScript错误和shadcn安装失败问题。
Complexity Levels
复杂度等级
Understanding complexity helps choose the right stack variation and design approach:
-
Micro Tool (single-purpose)
- Examples: Calculator, converter, color picker, timer
- Stack:
stacks/default-webapp.md - Focus: Simple, focused UI with minimal state
-
Content Showcase (information-focused)
- Examples: Landing page, portfolio, blog, documentation
- Stack:
stacks/content-showcase.md - Focus: Typography, reading experience, visual hierarchy
-
Light Application (multiple features with basic state)
- Examples: Todo list, meal planner, expense tracker
- Stack:
stacks/default-webapp.md - Focus: Feature clarity, data persistence, user flows
-
Complex Application (advanced functionality, multiple views)
- Examples: CRM, analytics dashboard, project management tool
- Stack: or
stacks/complex-application.mdstacks/data-dashboard.md - Focus: Navigation, state management, performance optimization
明确复杂度有助于选择合适的技术栈变体和设计方案:
-
微型工具(单一用途)
- 示例:计算器、转换器、颜色选择器、计时器
- 技术栈:
stacks/default-webapp.md - 重点:简洁聚焦的UI,最少化状态管理
-
内容展示类(信息导向)
- 示例:落地页、个人作品集、博客、文档站点
- 技术栈:
stacks/content-showcase.md - 重点:排版、阅读体验、视觉层级
-
轻型应用(多功能,基础状态管理)
- 示例:待办清单、饮食规划器、支出追踪工具
- 技术栈:
stacks/default-webapp.md - 重点:功能清晰度、数据持久化、用户流程
-
复杂应用(高级功能,多视图)
- 示例:CRM、分析仪表盘、项目管理工具
- 技术栈:或
stacks/complex-application.mdstacks/data-dashboard.md - 重点:导航、状态管理、性能优化
Core Tech Stack (Shared Foundation)
核心技术栈(通用基础)
All Spark App Template applications use this foundation:
所有Spark应用模板的应用都基于以下基础栈:
Build & Development
构建与开发
- Build Tool: Vite (latest stable)
- Framework: React 19+ (leverages new compiler, hooks, and features)
- Language: TypeScript
- Package Manager: pnpm
- Linting: Biome (ESLint fallback for complex plugins)
- 构建工具:Vite(最新稳定版)
- 框架:React 19+(利用新编译器、Hooks和特性)
- 开发语言:TypeScript
- 包管理器:pnpm
- 代码检查:Biome(复杂插件场景可降级使用ESLint)
Routing & Data
路由与数据
- Routing: TanStack Router (file-based, type-safe)
- Data Fetching: TanStack Query
- Forms: react-hook-form + Zod validation
- 路由:TanStack Router(基于文件、类型安全)
- 数据请求:TanStack Query
- 表单:react-hook-form + Zod 校验
Styling & UI
样式与UI
- Styling: Tailwind CSS v4+ (modern @import syntax)
- Components: shadcn/ui (New York style, 45+ components)
- Icons: Lucide React (1000+ icons)
- Color System: Radix Colors (OKLCH format)
- Theme: next-themes (single theme default, dark mode optional)
- 样式方案:Tailwind CSS v4+(现代化@import语法)
- 组件库:shadcn/ui(New York风格,45+组件)
- 图标库:Lucide React(1000+图标)
- 色彩系统:Radix Colors(OKLCH格式)
- 主题方案:next-themes(默认单主题,可选深色模式)
Utilities & Enhancement
工具与增强能力
- Animation: Motion (formerly framer-motion)
- Notifications: Sonner
- Utilities: CVA (or Tailwind Variants) + clsx + tailwind-merge
- Error Handling: react-error-boundary
- 动画:Motion(原framer-motion)
- 通知组件:Sonner
- 工具函数:CVA(或Tailwind Variants) + clsx + tailwind-merge
- 错误处理:react-error-boundary
Stack Variations
技术栈变体
All variations share the core foundation above. These templates add specific packages and design guidance:
所有变体都共享上述核心基础,这些模板额外添加了特定依赖包和设计指导:
Default Web App (stacks/default-webapp.md
)
stacks/default-webapp.md默认Web应用(stacks/default-webapp.md
)
stacks/default-webapp.md- Use for: Most applications, general-purpose tools
- Additive packages: None
- Design focus: Clean, modern, functional
- 适用场景:大部分应用、通用工具
- 额外依赖:无
- 设计重点:简洁、现代、实用
Data Dashboard (stacks/data-dashboard.md
)
stacks/data-dashboard.md数据仪表盘(stacks/data-dashboard.md
)
stacks/data-dashboard.md- Use for: Analytics, admin panels, data visualization
- Additive packages: Recharts (charts), date-fns (date handling)
- Design focus: Data density, hierarchical information, scanning patterns
- 适用场景:分析系统、管理后台、数据可视化
- 额外依赖:Recharts(图表)、date-fns(日期处理)
- 设计重点:数据密度、信息层级、快速浏览体验
Content Showcase (stacks/content-showcase.md
)
stacks/content-showcase.md内容展示类(stacks/content-showcase.md
)
stacks/content-showcase.md- Use for: Marketing sites, portfolios, blogs, documentation
- Additive packages: marked (markdown parsing)
- Design focus: Typography scale, reading experience, whitespace
- 适用场景:营销站点、个人作品集、博客、文档
- 额外依赖:marked(Markdown解析)
- 设计重点:排版层级、阅读体验、留白设计
Complex Application (stacks/complex-application.md
)
stacks/complex-application.md复杂应用(stacks/complex-application.md
)
stacks/complex-application.md- Use for: Multi-view apps, SaaS platforms, enterprise tools
- Additive packages: Zustand (state management), date-fns
- Design focus: Navigation patterns, state architecture, performance
- 适用场景:多视图应用、SaaS平台、企业级工具
- 额外依赖:Zustand(状态管理)、date-fns
- 设计重点:导航模式、状态架构、性能
React 19+ Features
React 19+ 特性
Enable these modern React capabilities:
启用以下React现代化能力:
React Compiler
React Compiler
- Status: Available in React 19+
- Benefits: Auto-memoization, significantly faster initial loads and interactions
- Setup: Compatible with React 17+, configure via compiler config
- 状态:React 19+已支持
- 优势:自动 memoization,大幅提升首屏加载和交互速度
- 配置:兼容React 17+,通过编译器配置开启
useActionState Hook
useActionState Hook
- Use for: Form handling, async actions, loading states
- Benefits: Simplified state management, built-in async handling
- Pattern: Consolidates form state, pending state, and error handling
- 适用场景:表单处理、异步操作、加载状态管理
- 优势:简化状态管理,内置异步处理能力
- 模式:整合表单状态、待处理状态和错误处理
useOptimistic Hook
useOptimistic Hook
- Use for: Instant UI updates before server confirmation
- Benefits: Improved perceived performance, better UX
- Pattern: Optimistic updates with automatic rollback on failure
- 适用场景:在服务器确认前优先更新UI
- 优势:提升感知性能,优化用户体验
- 模式:乐观更新,失败时自动回滚
Server Components
服务端组件
- Status: Stable in React 19+ (framework mode only)
- Frameworks: Next.js, TanStack Start
- Note: For Vite + React SPA apps, use client-side rendering
- 状态:React 19+已稳定(仅框架模式支持)
- 支持框架:Next.js、TanStack Start
- 注意:Vite + React SPA应用请使用客户端渲染
Project Structure Template
项目结构模板
my-app/
├── index.html
├── package.json
├── tsconfig.json
├── vite.config.ts
├── tailwind.config.js
├── biome.json
├── src/
│ ├── main.tsx # App entry point
│ ├── App.tsx # Root component
│ ├── index.css # Global styles + theme
│ ├── components/
│ │ ├── ui/ # shadcn components (don't edit)
│ │ └── ... # Custom components
│ ├── hooks/
│ │ └── use-mobile.tsx
│ ├── lib/
│ │ ├── utils.ts # cn() utility
│ │ └── data.ts # Data schemas (if needed)
│ └── routes/ # TanStack Router routes
│ └── __root.tsx
└── public/ # Static assetsmy-app/
├── index.html
├── package.json
├── tsconfig.json
├── vite.config.ts
├── tailwind.config.js
├── biome.json
├── src/
│ ├── main.tsx # 应用入口
│ ├── App.tsx # 根组件
│ ├── index.css # 全局样式 + 主题
│ ├── components/
│ │ ├── ui/ # shadcn组件(请勿修改)
│ │ └── ... # 自定义组件
│ ├── hooks/
│ │ └── use-mobile.tsx
│ ├── lib/
│ │ ├── utils.ts # cn()工具函数
│ │ └── data.ts # 数据 schema(按需添加)
│ └── routes/ # TanStack Router 路由
│ └── __root.tsx
└── public/ # 静态资源Design Philosophy
设计理念
Beautiful web applications transcend mere functionality - they evoke emotion and form memorable experiences. Follow these principles:
优秀的Web应用不止于功能完备——更要能唤起情感,留下难忘的使用体验。遵循以下原则:
Core Principles
核心原则
- Simplicity Through Reduction: Remove until reaching the simplest effective solution
- Material Honesty: Digital materials have unique properties; embrace them
- Obsessive Detail: Excellence emerges from hundreds of thoughtful decisions
- Coherent Design Language: Every element should feel like part of a unified system
- Distinctive Visual Identity: Create memorable aesthetics, not generic patterns
- 极简主义:不断精简,直到得到最简有效方案
- 材质诚实性:数字材质有其独特属性,应充分发挥
- 细节执念:优秀的体验源于数百个深思熟虑的决策
- 统一设计语言:所有元素都应属于同一个统一系统
- 独特视觉辨识度:打造 memorable 的美学设计,而非千篇一律的通用模板
Critical Requirements
强制要求
- Use OKLCH color format (mandatory for 2026)
- Avoid overused fonts: Inter, Roboto, Arial, Space Grotesk
- Choose distinctive typography: See
references/typography-pairings.md - Validate color contrast: WCAG AA (4.5:1 normal, 3:1 large text)
- Single theme by default: No dark mode unless explicitly requested
- Variable fonts: Use single variable font files for performance
See for comprehensive design guidance.
references/design-system.md- 使用OKLCH色彩格式(2026年起强制要求)
- 避免过度使用的字体:Inter、Roboto、Arial、Space Grotesk
- 选择有辨识度的排版:参考
references/typography-pairings.md - 色彩对比度校验:符合WCAG AA标准(普通文本4.5:1,大文本3:1)
- 默认单主题:除非明确要求,否则不提供深色模式
- 可变字体:使用单一可变字体文件提升性能
参考获取完整设计指导。
references/design-system.mdPerformance Targets (Core Web Vitals)
性能目标(核心Web指标)
Optimize for these metrics:
- INP (Interaction to Next Paint): < 200ms
- LCP (Largest Contentful Paint): < 2.5s
- CLS (Cumulative Layout Shift): < 0.1
Tools to achieve targets:
- React Compiler for automatic memoization
- Vite code-splitting and lazy loading
- Image optimization (WebP, AVIF, lazy loading)
- Font optimization (variable fonts, font-display: swap)
See for detailed optimization strategies.
references/performance-checklist.md针对以下指标优化:
- INP(交互到下一次绘制时间):< 200ms
- LCP(最大内容绘制时间):< 2.5s
- CLS(累积布局偏移):< 0.1
达成目标的工具:
- React Compiler实现自动memoization
- Vite代码分割和懒加载
- 图片优化(WebP、AVIF、懒加载)
- 字体优化(可变字体、font-display: swap)
参考获取详细优化策略。
references/performance-checklist.mdReferences
参考资料
Access detailed guidance in the directory:
references/- design-system.md - Comprehensive design philosophy, spatial composition, backgrounds, micro-interactions
- typography-pairings.md - Distinctive font combinations with personality guidance
- color-palettes.md - Pre-curated OKLCH palettes with WCAG validation
- component-patterns.md - Common shadcn compositions and usage patterns
- performance-checklist.md - Web Vitals optimization, React Compiler setup
- prd-template.md - Simplified planning framework for new apps
- radix-migration-guide.md - Base UI migration path for Radix concerns
可在目录下获取详细指导:
references/- design-system.md - 完整设计理念、空间布局、背景设计、微交互
- typography-pairings.md - 有辨识度的字体组合和风格指导
- color-palettes.md - 预 curated 的OKLCH配色方案,已通过WCAG校验
- component-patterns.md - 常用shadcn组合和使用模式
- performance-checklist.md - Web指标优化、React Compiler配置
- prd-template.md - 新应用简化规划框架
- radix-migration-guide.md - Radix相关需求的Base UI迁移路径
Implementation Workflow
实现工作流
Step 1: Initialize Project
步骤1:初始化项目
CRITICAL: Configure path aliases BEFORE running to avoid validation errors.
shadcn initbash
undefined重要提示:运行前先配置路径别名,避免校验错误。
shadcn initbash
undefinedCreate Vite project
创建Vite项目
pnpm create vite@latest my-app --template react-ts
pnpm create vite@latest my-app --template react-ts
Note: Working directory is now my-app/ - no need to cd
注:当前工作目录已为my-app/,无需执行cd命令
Install dependencies
安装依赖
pnpm install
pnpm install
Add Tailwind CSS and tooling
添加Tailwind CSS和相关工具
pnpm add -D tailwindcss@latest @tailwindcss/vite
pnpm add -D @biomejs/biome
pnpm add -D @tanstack/router-plugin
**Configure TypeScript Path Aliases** (Required for shadcn):
Update `tsconfig.json`*:
```json
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Update *:
tsconfig.app.jsonjson
{
"compilerOptions": {
// ... existing options ...
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Update *:
vite.config.tstypescript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
import path from 'path'
export default defineConfig({
plugins: [
TanStackRouterVite(),
react(),
tailwindcss(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
})* Configuration samples based on Vite + React + TypeScript template structure
Now shadcn init will succeed:
bash
undefinedpnpm add -D tailwindcss@latest @tailwindcss/vite
pnpm add -D @biomejs/biome
pnpm add -D @tanstack/router-plugin
**配置TypeScript路径别名**(shadcn必需配置):
更新`tsconfig.json`*:
```json
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}更新*:
tsconfig.app.jsonjson
{
"compilerOptions": {
// ... 现有配置 ...
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}更新*:
vite.config.tstypescript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
import path from 'path'
export default defineConfig({
plugins: [
TanStackRouterVite(),
react(),
tailwindcss(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
})* 配置示例基于Vite + React + TypeScript模板结构
现在shadcn init可顺利执行:
bash
undefinedInitialize shadcn (path aliases now configured)
初始化shadcn(路径别名已配置完成)
pnpm dlx shadcn@latest init
pnpm dlx shadcn@latest init
CRITICAL: Install shadcn components BEFORE writing custom components
重要提示:编写自定义组件前先安装shadcn组件
Identify which components you need first
先确认需要用到的组件
pnpm dlx shadcn@latest add button card input form dialog avatar badge separator
pnpm dlx shadcn@latest add button card input form dialog avatar badge separator
Add TanStack packages
添加TanStack相关包
pnpm add @tanstack/react-router @tanstack/react-query
pnpm add @tanstack/react-router @tanstack/react-query
Add utilities
添加工具依赖
pnpm add lucide-react motion sonner react-hook-form zod @hookform/resolvers
pnpm add clsx tailwind-merge class-variance-authority
pnpm add react-error-boundary next-themes
undefinedpnpm add lucide-react motion sonner react-hook-form zod @hookform/resolvers
pnpm add clsx tailwind-merge class-variance-authority
pnpm add react-error-boundary next-themes
undefinedStep 2: Configure Project
步骤2:配置项目
See stack templates in for specific configuration examples.
stacks/参考目录下的技术栈模板获取具体配置示例。
stacks/Step 3: Create PRD (Optional but Recommended)
步骤3:创建PRD(可选但推荐)
Use to plan:
references/prd-template.md- Purpose and mission
- Complexity level
- Essential features
- Design direction
- Color and typography choices
使用规划以下内容:
references/prd-template.md- 用途和目标
- 复杂度等级
- 核心功能
- 设计方向
- 色彩和排版选择
Step 4: Install shadcn Components FIRST
步骤4:优先安装shadcn组件
CRITICAL: Component Installation Order
ALWAYS install shadcn components BEFORE writing custom components that import them. This prevents TypeScript errors and failed builds.
❌ WRONG ORDER (causes errors):
bash
undefined重要提示:组件安装顺序
编写导入shadcn组件的自定义组件前,务必先安装对应的shadcn组件,避免出现TypeScript错误和构建失败。
❌ 错误顺序(会导致报错):
bash
undefined1. Write PersonDetail.tsx that imports '@/components/ui/card'
1. 编写导入'@/components/ui/card'的PersonDetail.tsx
2. Run pnpm dlx shadcn add card
2. 执行pnpm dlx shadcn add card
3. Fix TypeScript errors 'Cannot find module @/components/ui/card'
3. 修复「找不到模块@/components/ui/card」的TypeScript错误
✅ **CORRECT ORDER**:
```bash
✅ **正确顺序**:
```bash1. Plan which shadcn components you need
1. 规划需要用到的所有shadcn组件
Example: Card, Avatar, Badge, Separator, Button
示例:Card、Avatar、Badge、Separator、Button
2. Install ALL required shadcn components FIRST
2. 先安装所有需要的shadcn组件
pnpm dlx shadcn@latest add card avatar badge separator button
pnpm dlx shadcn@latest add card avatar badge separator button
3. Verify installation
3. 验证安装完成
ls src/components/ui/ # Should show: card.tsx, avatar.tsx, badge.tsx, etc.
ls src/components/ui/ # 应展示:card.tsx, avatar.tsx, badge.tsx等
4. NOW write PersonDetail.tsx that imports from '@/components/ui/*'
4. 现在编写从'@/components/ui/*'导入的PersonDetail.tsx
TypeScript will have proper types and components will exist
TypeScript会有正确的类型定义,组件也已存在
**Planning Checklist**:
1. List all UI components needed for your app
2. Identify which are shadcn components (Card, Button, etc.)
3. Run single `shadcn add` command with all components
4. Verify they exist in `src/components/ui/`
5. Write your custom components that import them
**规划检查清单**:
1. 列出应用所需的所有UI组件
2. 识别哪些是shadcn组件(Card、Button等)
3. 执行单次`shadcn add`命令安装所有组件
4. 验证组件已存在于`src/components/ui/`目录下
5. 编写导入这些组件的自定义组件Step 5: Implement with Best Practices
步骤5:遵循最佳实践实现
- Follow shadcn component patterns
- Use OKLCH colors in CSS variables
:root - Implement responsive design (mobile-first)
- Add error boundaries
- Optimize images and fonts
- Test Core Web Vitals
- 遵循shadcn组件使用模式
- 在CSS变量中使用OKLCH色彩
:root - 实现响应式设计(移动端优先)
- 添加错误边界
- 优化图片和字体
- 测试核心Web指标
Common Patterns
常用模式
Theme Configuration (index.css)
主题配置(index.css)
css
@import 'tailwindcss';
:root {
/* OKLCH colors - mandatory format */
--background: oklch(0.97 0.01 75);
--foreground: oklch(0.25 0.02 55);
--primary: oklch(0.52 0.14 155);
--accent: oklch(0.72 0.13 55);
/* Add more theme variables */
--radius: 0.75rem;
}
@theme {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-accent: var(--accent);
/* Radius system */
--radius-sm: calc(var(--radius) * 0.5);
--radius-md: var(--radius);
--radius-lg: calc(var(--radius) * 1.5);
}Note: Uses Tailwind CSS v4+ @import syntax. For v3, use @tailwind directives instead.
css
@import 'tailwindcss';
:root {
/* OKLCH 色彩 - 强制格式 */
--background: oklch(0.97 0.01 75);
--foreground: oklch(0.25 0.02 55);
--primary: oklch(0.52 0.14 155);
--accent: oklch(0.72 0.13 55);
/* 添加更多主题变量 */
--radius: 0.75rem;
}
@theme {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-accent: var(--accent);
/* 圆角系统 */
--radius-sm: calc(var(--radius) * 0.5);
--radius-md: var(--radius);
--radius-lg: calc(var(--radius) * 1.5);
}注:使用Tailwind CSS v4+ @import语法,v3版本请使用@tailwind指令替代。
Form Handling
表单处理
tsx
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
const schema = z.object({
email: z.string().email(),
password: z.string().min(8)
});
function LoginForm() {
const form = useForm({
resolver: zodResolver(schema),
defaultValues: { email: '', password: '' }
});
async function onSubmit(data: z.infer<typeof schema>) {
// Handle form submission
}
return <form onSubmit={form.handleSubmit(onSubmit)}>...</form>;
}tsx
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
const schema = z.object({
email: z.string().email(),
password: z.string().min(8)
});
function LoginForm() {
const form = useForm({
resolver: zodResolver(schema),
defaultValues: { email: '', password: '' }
});
async function onSubmit(data: z.infer<typeof schema>) {
// 处理表单提交
}
return <form onSubmit={form.handleSubmit(onSubmit)}>...</form>;
}Data Fetching
数据请求
tsx
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
function UserList() {
const queryClient = useQueryClient();
const { data, isLoading } = useQuery({
queryKey: ['users'],
queryFn: fetchUsers
});
const createUser = useMutation({
mutationFn: createUserAPI,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['users'] });
}
});
if (isLoading) return <LoadingSpinner />;
return <UserGrid users={data} onCreate={createUser.mutate} />;
}tsx
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
function UserList() {
const queryClient = useQueryClient();
const { data, isLoading } = useQuery({
queryKey: ['users'],
queryFn: fetchUsers
});
const createUser = useMutation({
mutationFn: createUserAPI,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['users'] });
}
});
if (isLoading) return <LoadingSpinner />;
return <UserGrid users={data} onCreate={createUser.mutate} />;
}Troubleshooting
问题排查
Radix UI Maintenance Concerns
Radix UI维护问题
Radix UI is receiving fewer updates. For new projects or migration concerns:
- See for Base UI migration path
references/radix-migration-guide.md - shadcn/ui now supports Base UI as an alternative
- React Aria is another excellent option (Adobe-backed, superior accessibility)
Radix UI的更新频率有所降低,针对新项目或迁移需求:
- 参考获取Base UI迁移路径
references/radix-migration-guide.md - shadcn/ui现已支持Base UI作为替代方案
- React Aria也是优秀的选择(Adobe支持,可访问性更优)
Performance Issues
性能问题
If app feels slow:
- Enable React Compiler for automatic memoization
- Check Core Web Vitals in Chrome DevTools
- Use
references/performance-checklist.md - Consider code-splitting with TanStack Router's lazy loading
如果应用运行卡顿:
- 开启React Compiler实现自动memoization
- 在Chrome DevTools中检查核心Web指标
- 使用排查
references/performance-checklist.md - 考虑使用TanStack Router的懒加载实现代码分割
Build Tool Alternatives
构建工具替代方案
Newer Vite versions with Rolldown bundler may offer faster builds when stable. Monitor for stable releases.
集成Rolldown打包器的新版本Vite稳定后可能会提供更快的构建速度,可关注稳定版发布。
System Requirements
系统要求
- Node.js: 18+ (or current LTS version)
- Package Manager: pnpm recommended for performance
- OS: macOS, Linux, or Windows with WSL2
- Node.js:18+(或当前LTS版本)
- 包管理器:推荐使用pnpm以获得更好的性能
- 操作系统:macOS、Linux或安装WSL2的Windows
Next Steps
后续步骤
After scaffolding:
- Review the stack template for your complexity level
- Consult design references for styling
- Create a PRD to plan features and design
- Implement following best practices
- Optimize for Core Web Vitals
- Deploy to production (Vercel, Netlify, etc.)
Remember: The goal is functional and performant web applications. Start simple, iterate based on user needs, and prioritize user experience over technical complexity.
项目初始化完成后:
- 查看对应复杂度等级的技术栈模板
- 参考设计资料完成样式设计
- 创建PRD规划功能和设计
- 遵循最佳实践实现功能
- 针对核心Web指标优化
- 部署到生产环境(Vercel、Netlify等)
牢记:最终目标是打造功能完备、性能优秀的Web应用。从简单起步,基于用户需求迭代,优先保障用户体验而非技术复杂度。