home / skills / dexploarer / claudius-skills / react-component-generator

This skill generates modern React components with TypeScript, hooks, and styling, helping you scaffold reliable UI code quickly.

npx playbooks add skill dexploarer/claudius-skills --skill react-component-generator

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
2.2 KB
---
name: react-component-generator
description: Generates React components with TypeScript, hooks, and best practices. Use when user asks to "create React component", "generate component", or "scaffold component".
allowed-tools: [Write, Read, Glob]
---

# React Component Generator

Generates modern React components following best practices with TypeScript support.

## When to Use

- "Create a Button component"
- "Generate a UserProfile component"
- "Scaffold a DataTable component"

## Instructions

### 1. Gather Requirements
- Component name (PascalCase)
- Component type (functional, with state, with effects)
- Props needed
- TypeScript types
- Styling approach

### 2. Generate Component Structure

**Functional Component:**
```typescript
import React from 'react';
import styles from './ComponentName.module.css';

interface ComponentNameProps {
  // Props here
}

export const ComponentName: React.FC<ComponentNameProps> = ({
  // Destructure props
}) => {
  return (
    <div className={styles.container}>
      {/* Component JSX */}
    </div>
  );
};
```

**With State:**
```typescript
import React, { useState } from 'react';

export const ComponentName: React.FC<Props> = () => {
  const [state, setState] = useState<Type>(initialValue);

  return <div>{/* ... */}</div>;
};
```

**With Effects:**
```typescript
import React, { useEffect } from 'react';

export const ComponentName: React.FC<Props> = () => {
  useEffect(() => {
    // Effect logic
    return () => {
      // Cleanup
    };
  }, [dependencies]);

  return <div>{/* ... */}</div>;
};
```

### 3. Add PropTypes/TypeScript Interfaces

```typescript
interface ComponentNameProps {
  title: string;
  onAction?: () => void;
  children?: React.ReactNode;
  className?: string;
}
```

### 4. Create Associated Files

- `ComponentName.tsx` - Component file
- `ComponentName.module.css` - Styles
- `ComponentName.test.tsx` - Tests
- `index.ts` - Barrel export

### 5. Add Documentation

```typescript
/**
 * ComponentName - Brief description
 *
 * @example
 * <ComponentName title="Hello" onAction={handleClick} />
 */
```

## Best Practices

- Use functional components
- TypeScript for type safety
- CSS Modules for styling
- Proper prop destructuring
- Meaningful names
- Add tests
- Export from index.ts

Overview

This skill generates production-ready React components using TypeScript, hooks, and common best practices. It scaffolds files, types, styles, and simple tests so you get a working, typed component quickly. Use it to standardize component shape across projects and reduce boilerplate.

How this skill works

It asks for component name, desired behavior (stateless, stateful, or effectful), props and TypeScript types, and preferred styling approach. Then it outputs a component file, a CSS module or chosen style file, a test scaffold, and an index export with inline documentation and appropriate imports. The result follows functional component patterns, prop typing, and small, testable structure suitable for immediate use.

When to use it

  • You want to create a new UI component (e.g., Button, Modal, Avatar).
  • You need a typed component scaffold with props and default patterns.
  • You want a component with state or side effects (useState/useEffect) set up.
  • You need consistent file structure: .tsx, styles, test, and index export.
  • You want an example usage block and prop interface for documentation.

Best practices

  • Use PascalCase for component names and meaningful prop names.
  • Prefer functional components with hooks for state and effects.
  • Define a clear TypeScript props interface and export it when reused.
  • Keep styling modular (CSS Modules or styled-components) to avoid global leakage.
  • Add a simple unit test and a barrel export (index.ts) for easy imports.
  • Document examples and expected usage in a JSDoc comment above the component.

Example use cases

  • Generate a stateless Button with typed onClick and className props plus a CSS module.
  • Scaffold a UserProfile component that fetches data in useEffect and types the response.
  • Create a DataTable component with local sorting state using useState and typed row props.
  • Produce a Modal component with accessible props (isOpen, onClose) and an example usage block.
  • Create a small form component with controlled inputs and TypeScript form value types.

FAQ

Can this generate class components?

No — the generator produces modern functional components using hooks and TypeScript; update manually if you need class components.

Will it add runtime PropTypes and TypeScript?

It prioritizes TypeScript interfaces for static typing. You can add PropTypes manually if your project requires runtime checks.