跳到正文
Skillpedia
网站与界面(前端)40k · #7382

react-container-presentation-component

它能做什么

这个工具可以为使用 React 构建的网站或应用创建代码组件。它会按照一种叫“容器/展示”(Container/Presentation)的模式来组织代码,让代码结构更清晰。

适用场景

  • ✓当你想为 React 项目新建一个代码组件时。
  • ✓当你需要按照某种特定模式,更好地组织项目代码时。
  • ✓当你希望代码遵循既定的组织和风格规范时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/react-container-presentation-component/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/react-container-presentation-component/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请按照 Container/Presentation 模式创建一个名为“UserProfile”的 React 组件,分类为“ui”。”

每周 5 个新技能,1 分钟读完。

工作原理

你需要提供组件名称,并指定它是“ui”(界面)还是“features”(功能)组件。然后工具会按照项目的组织和风格规范,创建所需的文件。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Container/Presentation Component

Use this skill to create a React component under src/components that follows the Container/Presentation pattern.

Refer to this skill's bundled references for detailed rules.

  • references/component-architecture.md
  • references/typescript-and-scss-rules.md

If the /react-container-presentation-component input is incomplete, ask questions first before creating files.

When To Use

  • When the user runs /react-container-presentation-component
  • When the user explicitly asks for a React component that follows the Container/Presentation pattern
  • When the user wants help deciding or implementing ui vs features classification within the Container/Presentation pattern

Required Questions

If any of the following information is missing, ask the user using ask_user.

  1. Component name
  2. Type (ui or features)
  3. Whether to replace existing components (only when creating ui)

Question requirements:

  • Provide the type as options (ui, features)
  • Require the component name to be in PascalCase
  • For ui, ask whether direct usage of Mantine or other UI libraries in existing features should be replaced with the new component

Procedure

  1. Check existing components
  • Check whether src/components/ui/<ComponentName> or src/components/features/<ComponentName> already exists.
  • If it exists, do not overwrite; confirm the preferred approach with the user.
  1. Decide target directory
  • ui: src/components/ui/<ComponentName>
  • features: src/components/features/<ComponentName>
  1. Re-check classification (only when ui is specified)
  • Even when ui is specified, before creating files, review Reclassification Rule in references/component-architecture.md.
  • If the implementation includes state management, side effects, async processing, context/store updates, or business logic, treat it as features.
  • If the result is closer to features, do not proceed as ui; use ask_user and confirm one of the following before continuing.
    • Create as features
    • Keep ui and move state/logic to parent or features
  1. Create required files
  • ui: index.tsx, index.module.scss, index.stories.tsx
  • features: index.tsx, use<ComponentName>.tsx, presentation.tsx, types.ts, presentation.module.scss, presentation.stories.tsx
  1. Replace existing usages (only when creating ui)
  • Only when the user approves, replace equivalent direct implementations using Mantine or other UI libraries in existing features with the new ui component.
  1. Validate
  • Run build and lint commands, and ensure both pass; if issues are introduced by newly added or updated files, fix them.
  • Follow Storybook Minimum in references/component-architecture.md for story state decisions.
  • Ask the user via ask_user whether to run a Storybook check (for example: "Run" / "Skip for now").
  • Run npm run storybook only if the user selects "Run".
  • If the user selects "Skip for now", explicitly mention in the final report that Storybook execution was skipped.

Output Contract

  • Report the list of files created.
  • If replacements were performed, report the list of changed files and replacement details.
  • Provide one usage example of the created component.
  • Report whether Storybook verification was executed (run/skip), and if run, include the command used.
  • Explain why the component was classified as ui or features.
  • Summarize where state, side effects, and rendering responsibilities were placed.
  • Confirm whether there were any dependency direction violations.
  • Clearly state any unresolved items.
常见问题

什么是 Container/Presentation 模式?

这是一种组织代码的方式:一个组件(“容器”)负责处理逻辑和数据,另一个组件(“展示”)只负责如何把内容显示在屏幕上。

“ui”和“features”分别是什么?

“ui”组件只负责外观,比如按钮或文本框。“features”组件带有逻辑,比如获取数据或管理表单。

如果同名组件已经存在怎么办?

工具不会自动覆盖。它会询问你希望怎么处理,比如重命名,或者不再创建该组件。

详情

作者的原始描述

Create a React component using the Container/Presentation pattern in src/components by asking for the component name and type (ui or features), then scaffold files that follow this repository's TypeScript, Storybook, and SCSS conventions. Use when the user explicitly asks for a Container/Presentation-based component or runs /react-container-presentation-component.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7382
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能