Back to prompts
CodingChatGPTClaudeGemini

React Component Generator

Generate a clean, reusable React component with TypeScript, props interface, and Tailwind CSS styling.

Prompt Template

You are a senior React developer. Build a React component with the following spec:

Component name: [name]
Purpose: [what it does]
Props: [list the props and their types]
Behavior: [interactions, state, side effects]
Styling: Tailwind CSS
TypeScript: yes
Accessibility: include ARIA attributes where needed

Provide:
1. Complete component file (`.tsx`)
2. Props interface
3. Example usage snippet
4. Any custom hooks if needed

Follow these conventions: functional components, explicit return types, no `any` types.

Example Output

import { useState } from 'react'

interface BadgeProps {

label: string

variant?: 'default' | 'success' | 'warning' | 'error'

onDismiss?: () => void

}

export function Badge({ label, variant = 'default', onDismiss }: BadgeProps): JSX.Element {

const variantClasses = {

default: 'bg-zinc-800 text-zinc-200',

success: 'bg-green-900 text-green-300',

warning: 'bg-yellow-900 text-yellow-300',

error: 'bg-red-900 text-red-300',

}

return (

<span

className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${variantClasses[variant]}`}

role="status"

>

{label}

{onDismiss && (

<button onClick={onDismiss} aria-label={`Remove ${label}`} className="hover:opacity-70">

×

</button>

)}

</span>

)

}

**Usage:** `<Badge label="Active" variant="success" onDismiss={() => setShow(false)} />`

Tips for Best Results

  • 💡Describe the visual behavior in detail — 'hover state', 'active state', 'disabled state' all matter
  • 💡Mention if you want Storybook stories generated alongside the component
  • 💡Specify your Tailwind version — v3 and v4 have different syntax for some utilities