---
name: javascript-react-component-generator
description: "Generates a complete, typed React component with props, state and your chosen styling approach, written to current best practice and ready to drop in. Use when a developer needs a complete React function component with typed props, local state and the chosen styling, ready to paste. Do not use for a whole app architecture or class component migration. Related topics: react, javascript, coding."
---

# JavaScript React Component Generator

Generates a complete, typed React component with props, state and your chosen styling approach, written to current best practice and ready to drop in.

## When to use

Use this skill when a developer needs a complete React function component with typed props, local state and the chosen styling, ready to paste. Do not use it for a whole app architecture or class component migration.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Define the props with types or JSDoc and defaults, until every named prop is declared.
3. Implement state and the selected functionality at the lowest sensible level, until no value is stored that could be derived.
4. Handle loading, error and empty states for any fetch and clean up on unmount, until each state renders something.
5. Apply the chosen styling approach and accessible markup, until interactive elements have names and keyboard support.
6. Add a usage example and two lines on design choices, until the example runs with the declared props.

## Inputs

- **Component name** (free text, e.g. "UserProfileCard")
- **State management** (choose one: useState and useEffect, Redux, Context API, None - stateless)
- **Styling approach** (choose one: Tailwind CSS, Styled Components, CSS Modules, Inline Styles)
- **Use TypeScript** (choose one: Yes, No)
- **Props it accepts** (longer free text)
- **Main functionality** (choose any: Fetch data on mount, Handle click events, Form Validation, Animations)

## Output

The component code in one block, a short usage example, and two lines on the design choices.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### React Component Generator

Generate a clean, reusable React component.

- Component name: {{Component name}}
- State management: {{State management}}
- Styling approach: {{Styling approach}}
- Use TypeScript: {{Use TypeScript}}
- Props it accepts: {{Props it accepts}}
- Main functionality: {{Main functionality}}

Write a function component with typed or documented props, sensible defaults, and a single responsibility. Keep state as local as it can be and derive values instead of storing them. For data fetching, handle loading, error and empty states, and cancel the request on unmount. Make interactive elements real buttons or inputs with accessible names and keyboard support. Use the chosen styling approach consistently.

Return the component code, then a short usage example, then two lines on design choices.

## Pitfalls

- Storing derived data in state, which causes stale values.
- Fetching without cancelling on unmount or handling errors.
- Using div elements with click handlers instead of real buttons.
