Skip to content
Back to skills

Add Component

ASecurity

Create a React component with TypeScript and optional tests

  • 666 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
developmenttypescriptbashreactnodetestingapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add majiayu000/claude-skill-registry --skill add-component --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Add Component?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Add Component
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-add-component-claude-skill-registry/badge)](https://www.skillsdirectory.com/skills/majiayu000-add-component-claude-skill-registry)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
skill: add-component
description: Create a React component with TypeScript and optional tests
arguments: component name and optional props description
---

# Add Component: $ARGUMENTS

Create a new React component with proper TypeScript types.

## Process

### 1. Determine Component Type

Based on the name and description:
- **UI Component**: Presentational, receives props
- **Container**: Manages state, fetches data
- **Layout**: Wraps other components
- **Form**: Handles user input

### 2. Create Component File

Location: `components/[ComponentName].tsx`

```tsx
'use client'; // if using hooks or browser APIs

import { useState } from 'react';

interface ComponentNameProps {
  // Define props
  title: string;
  onAction?: () => void;
}

export default function ComponentName({ title, onAction }: ComponentNameProps) {
  return (
    <div data-testid="component-name" className="p-4">
      <h2>{title}</h2>
      {onAction && (
        <button onClick={onAction} data-testid="action-button">
          Action
        </button>
      )}
    </div>
  );
}
```

### 3. Add to Exports (if using barrel exports)

```typescript
// components/index.ts
export { default as ComponentName } from './ComponentName';
```

### 4. Create Test File (optional but recommended)

```typescript
// components/ComponentName.test.tsx
import { render, screen, fireEvent } from '@testing-library/react';
import ComponentName from './ComponentName';

describe('ComponentName', () => {
  test('renders with title', () => {
    render(<ComponentName title="Test" />);
    expect(screen.getByText('Test')).toBeInTheDocument();
  });

  test('calls onAction when button clicked', () => {
    const handleAction = jest.fn();
    render(<ComponentName title="Test" onAction={handleAction} />);
    fireEvent.click(screen.getByTestId('action-button'));
    expect(handleAction).toHaveBeenCalled();
  });
});
```

### 5. Validate

```bash
npm run build
npm run lint
```

## Component Patterns

**Controlled input:**
```tsx
interface InputProps {
  value: string;
  onChange: (value: string) => void;
}
```

**With children:**
```tsx
interface WrapperProps {
  children: React.ReactNode;
}
```

**With ref:**
```tsx
const Component = forwardRef<HTMLDivElement, Props>((props, ref) => {
  return <div ref={ref} {...props} />;
});
```

**With default props:**
```tsx
interface Props {
  size?: 'sm' | 'md' | 'lg';
}

function Component({ size = 'md' }: Props) { ... }
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.