---
name: react-component-builder
description: "A complete React component from a props and state spec, wired to your styling approach and libraries, with an optional Jest and Testing Library skeleton so it slots into the codebase on day one. Use when a new React component needs writing from a spec of props, state, styling approach, and the libraries it has to work with. Do not use for documenting or reviewing an existing component, or building a whole page layout. Related topics: coding, react."
---

# React Component Builder

A complete React component from a props and state spec, wired to your styling approach and libraries, with an optional Jest and Testing Library skeleton so it slots into the codebase on day one.

## When to use

Use this skill when a new React component needs writing from a spec of props, state, styling approach, and the libraries it has to work with. Do not use it for documenting or reviewing an existing component, or building a whole page layout.

## 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. Write the props interface or PropTypes block so it matches the spec exactly, with a default for each optional prop.
3. Implement the component with local state only where required, deriving values during render rather than duplicating them in state.
4. Integrate each selected library the idiomatic way and apply the chosen styling approach without mixing in another.
5. When tests are requested, write a Jest and Testing Library file that covers render, one interaction, and one state change.
6. Add a short note on file placement and imports, and confirm the code has no unused imports or props.

## Inputs

- **Component name** (free text, e.g. "MyComponent")
- **Component type** (choose one: Functional, Class)
- **Props** (longer free text)
- **State required** (choose one: Yes, No)
- **Styling** (choose one: CSS Modules, Styled-Components, Tailwind, Inline Styles)
- **Include tests** (choose one: Yes, No)
- **Libraries in use** (choose any: Redux, React Router, Axios, Formik)

## Output

A markdown document with a code block for the component file, an optional second block for the test file, and a three-line placement note.

## Prompt template

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

### React Component

Build a React component to this spec.

- Component name: {{Component name}}
- Component type: {{Component type}}
- Props: {{Props}}
- State required: {{State required}}
- Styling: {{Styling}}
- Include tests: {{Include tests}}
- Libraries in use: {{Libraries in use}}

Define the props as a TypeScript interface or PropTypes block that matches the list exactly, with defaults for optional props. Keep state local and minimal; derive values in render rather than storing them. Wire the selected libraries the way they are used in a real app: a hook for Redux, Link or useNavigate for React Router, a cancellable request for Axios, a form config for Formik. Apply the styling approach without mixing in another. Name handlers handleX and keep the component under roughly 150 lines; split a helper out when it grows past that. When tests are requested, cover rendering with required props, one interaction, and one state change using Jest and Testing Library.

Return a markdown document with one code block for the component file named after the component, then, if requested, a second code block for the test file. Add a three-line note on where the file goes and what to import.

## Pitfalls

- Copying a prop into state on mount, which goes stale the moment the parent re-renders with a new value.
- Mixing Tailwind classes into a CSS Modules component, so styles end up in two systems nobody can reconcile.
- Firing an Axios request in useEffect without cancelling it, which sets state on an unmounted component.
