1 条规则
This is a set of rules that outlines the best practices and architecture principles to create Plasmic-compatible code:
Plasmic-Specific Guidelines
- Build reusable components for Plasmic Studio, not pages
- Pass as much UI work as possible to Plasmic Studio
- For repeatable components, use string/number props over slots
- Use slot components for images when possible; apply default styles with ".element image" selectors
- Use DataProvider only when exposing data to Plasmic Studio is necessary
- Use the Plasmic state feature if you need to listen to or propagate changes
Component Registration
- Register all components in plasmic-host.tsx
- Import components at the top of the file
- Use registerComponent with proper configuration (see Plasmic docs)
- Set appropriate name and displayName
- Use importPath with @/ prefix only in codegen mode (if loader library is absent)
- Provide default values for required props
- Add descriptive comments for each prop
- By default, registerComponent includes a className prop for root styles (do not add it explicitly)
Props Configuration
- Use type: "class" for all className props (never "string")
- For eventHandler props, include argTypes: []
- Use these types for props:
- "string" for text
- "number" for numbers
- "boolean" for toggles
- "imageUrl" for images
- "array" for collections
- "eventHandler" for callbacks
- "slot" for customizable content
- "class" for styles
Naming Conventions
- PascalCase: Components, Types, Interfaces
- kebab-case: directories, file names (e.g., auth-wizard, user-profile.tsx)
- camelCase: variables, functions, methods, hooks, props
- UPPERCASE: environment variables, constants
- Prefix event handlers with 'handle' (e.g., handleClick)
- Prefix booleans with verbs (e.g., isLoading, hasError)
- Prefix custom hooks with 'use' (e.g., useAuth)
- For style props, use suffix ClassName (e.g., titleClassName)
- For event handlers, use prefix on (e.g., onClick)
Styling Guidelines
- Use CSS modules (e.g., ComponentName.module.css)
- Design mobile-first and responsively
- Include hover states and transitions for interactive elements
- Add fallback styles for missing content (e.g., no-image state)
- Ensure color contrast accessibility
- Maintain consistent spacing
- Define CSS variables for theme colors and spacing
- Use Plasmic's registerToken/tokens for CSS variable integration
- Pass className for root element to allow Studio style customization
- Use classnames feature to allow Studio to override/modify child styles
- Allow initial CSS in UI components for Studio users to extend
Data & State Handling
- Use DataProvider only when exposing data to Studio is needed (in case if user would need to render something using the data, like a repeatable component, or if the component itself is created to fetch the data)
- Transform data inside the component as needed
- Define states in registration when needed, with correct valueProps/onChangeProps/variableType
- When using data sources (like fetching data from remote database) - use data fetching components, look up supabase example repository to see how it's done
Common Mistakes to Avoid
- Do not create pages; only reusable components
- Do not use type: "string" for className props (use "class")
- Do not use slots for repeatable components populated from data
- Do not forget argTypes: [] for eventHandler props
- Do not forget providesData: true when using DataProvider
- Do not add className prop again in registration
- Do not use app router features without confirming project structure
- Use "dynamic" clause to load registered components that rely on heavy front-end dependencies (like google maps, etc.)相关插件
Next.js↓ 36.8k
Next.js 在 Cursor 中的规则与最佳实践。Front End↓ 32.1k
Front End 在 Cursor 中的规则与最佳实践。Web Development↓ 2.7k
Web Development 在 Cursor 中的规则与最佳实践。Frontend Architecture↓ 234
Frontend Architecture 在 Cursor 中的规则与最佳实践。Buddy Os↓ 4
Buddy Os 在 Cursor 中的规则与最佳实践。Nextjs 16↓ 0
面向 Cursor 的 Next.js 16 App Router 规则,针对 2025-10 版本:Cache Components(取代 dynamicIO/ppr/useCache 标志)、proxy.ts(由 middleware.ts 改名)、仅异步的请求 API(cookies/headers/params/searchParams)、双参数 revalidateTag(tag, profile)、Server Actions 的 updateTag + refresh、Turbopack 默认启用、移除 next lint、图像生成器中的异步 params、parallel-route 默认 default.js。Monorepo Tamagui↓ 4k
Monorepo Tamagui 在 Cursor 中的规则与最佳实践。React Native↓ 3.3k
React Native 在 Cursor 中的规则与最佳实践。