React component generator

From einverne/dotfiles · View interactive version

React component generator is an AI agent skill from the GitHub repository einverne/dotfiles. 生成符合项目规范的 React 组件。当用户要求创建组件、新建 React 组件或生成组件文件时使用

How to use this skill

Skill file

React 组件生成器

组件规范

项目使用以下约定:

生成流程

  1. 确认组件信息
  1. 创建文件结构

```

src/components/{ComponentName}/

├── index.tsx

├── {ComponentName}.module.css

└── {ComponentName}.test.tsx

```

  1. 生成组件文件

index.tsx 模板:

import React from 'react';
import styles from './{ComponentName}.module.css';

interface {ComponentName}Props {
  // 定义 props 类型
}

/**
 * {组件描述}
 * @param props - 组件属性
 */
export const {ComponentName}: React.FC<{ComponentName}Props> = (props) => {
  return (
    <div className={styles.container}>
      {/* 组件内容 */}
    </div>
  );
};
  1. 生成样式文件

{ComponentName}.module.css 模板:

.container {
  /* 组件样式 */
}
  1. 生成测试文件

{ComponentName}.test.tsx 模板:

import { render, screen } from '@testing-library/react';
import { {ComponentName} } from './index';

describe('{ComponentName}', () => {
  it('renders correctly', () => {
    render(<{ComponentName} />);
    // 添加断言
  });
});

质量检查

生成后自动运行:

  1. TypeScript 类型检查:npm run type-check
  2. ESLint 检查:npm run lint
  3. 测试:npm test -- {ComponentName}

如有错误,显示错误信息并提供修复建议。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.