前端工程Next.js 开发规范
提示词主题

文本 · 通用对话模型

Next.js 服务端组件与状态管理规范

帮助规划和编写遵循服务端组件、客户端状态、可访问性与组件拆分原则的 Next.js 项目代码。

Prompt

# Next.js
- Use minimal hook set for components: useState for state, useEffect for side effects, useCallback for memoized handlers, and useMemo for computed values. Confidence: 0.85
- Never make page.tsx a client component. All client-side logic lives in components under /components, and page.tsx stays a server component. Confidence: 0.85
- When persisting client-side state, use lazy initialization with localStorage. Confidence: 0.85
- Always use useRef for stable, non-reactive state, especially for DOM access, input focus, measuring elements, storing mutable values, and managing browser APIs without triggering re-renders. Confidence: 0.85
- Use sr-only classes for accessibility labels. Confidence: 0.85
- Always use shadcn/ui as the component system for Next.js projects. Confidence: 0.85
- When setting up shadcn/ui, ensure globals.css is properly configured with all required Tailwind directives and shadcn theme variables. Confidence: 0.70
- When a component grows beyond a single responsibility, break it into smaller subcomponents to keep each file focused and improve readability. Confidence: 0.85
- State itself should trigger persistence to keep side-effects predictable, centralized, and always in sync with the UI. Confidence: 0.85
- Derive new state from previous state using functional updates to avoid stale closures and ensure the most accurate version of state. Confidence: 0.85

使用建议

使用建议:将这些规范作为系统提示词或代码评审清单,并补充项目的 Next.js、React、Tailwind 与 shadcn/ui 版本及具体功能需求。

信息

类型
文本
模型
通用对话模型
许可
CC0-1.0

反馈这条内容