react
React rules for the project Applies to files matching: **/*.tsx.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Components
- Prefer function components: Use React function components with hooks over class components.
-
Client vs server: Mark interactive components with
"use client"at the top of the file; keep non-interactive logic in server components or libraries. - No default exports: Use named exports for all components.
Hooks
- Hook ordering: Follow the standard rules of hooks; no conditional or looped hooks.
-
Derived state: Prefer deriving values from props/form state instead of duplicating them in
useState. -
Effects: Keep
useEffectminimal and side effect focused; avoid using it for basic data derivation.
Forms
-
Validation: Use
react-hook-form+ Zod for all non-trivial forms. -
UI primitives: Prefer shadcn
Formprimitives (Form,FormField,FormItem,FormLabel,FormControl,FormMessage) for form layout and error handling. - Schema location: Co-locate small form schemas with the component; extract only when reused across modules.
Styling & Layout
-
Class merging: Use the shared
cnutility for conditional classes. - Composition: Prefer smaller composed components over deeply nested JSX in a single component.
Configuration Access
-
Client components: Always use
useConfig()from@/components/config-providerto access site configuration in client components ("use client"). -
Never import
siteConfigdirectly in client components—it derives values from server-only environment variables. TheConfigProviderreceives a serialized version that decouples client code from server secrets.
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-02-05
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!