---
name: react-component-formatter
description: "A lint-clean React component file in house style: explicit PropTypes with defaults, a consistent export, the state approach you chose, and matching CSS module and test stubs named to convention. Use when a React component must be written or reshaped to a house style with PropTypes, default values, a fixed export form, and no lint warnings. Do not use for adding features to a component, reviewing its logic, or writing its documentation. Related topics: coding, react."
---

# React Component Formatter

A lint-clean React component file in house style: explicit PropTypes with defaults, a consistent export, the state approach you chose, and matching CSS module and test stubs named to convention.

## When to use

Use this skill when a React component must be written or reshaped to a house style with PropTypes, default values, a fixed export form, and no lint warnings. Do not use it for adding features to a component, reviewing its logic, or writing its documentation.

## 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. Lay the file out in the fixed order: imports, constants, component, PropTypes, defaults, export.
3. Declare every prop in PropTypes with isRequired where stated and a default for each optional prop.
4. Apply the chosen state approach only, and keep hooks at the top level with keys on every list item so the react-hooks rules pass.
5. When a CSS module is requested, create it with camelCase class names and reference it through a styles import.
6. Check the file against the recommended react lint rules and remove any unused import or variable.

## Inputs

- **Component name** (free text, e.g. "MyComponent")
- **Component type** (choose one: Functional, Class)
- **Props** (longer free text)
- **State management** (choose one: useState, useReducer, Redux, none)
- **Include CSS module** (choose one: Yes, No)
- **Export style** (choose one: default export, named export)

## Output

The component file in a labeled code block, then the CSS module and any test stub as separate code blocks, each headed by its filename.

## Prompt template

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

### React Component Formatter

Produce a lint-ready React component file to this spec.

- Component name: {{Component name}}
- Component type: {{Component type}}
- Props: {{Props}}
- State management: {{State management}}
- Include CSS module: {{Include CSS module}}
- Export style: {{Export style}}

The point of this file is consistency: someone should be able to open it next to any other component in the repo and see the same layout. Order the file as imports, constants, the component, PropTypes, defaults (defaultProps for a class component, default parameter values for a functional one), then the export. Declare every prop in PropTypes with isRequired where stated, and give every optional prop a default so the component never reads undefined. Use the selected state approach only: a reducer for useReducer, a connected hook for Redux, nothing for none. When a CSS module is requested, name it after the component and reference it through a styles import with camelCase class names. Keep the code free of lint warnings under the recommended react and react-hooks rules: no unused variables, hooks at the top level, keys on list items.

Return the component file in a code block labeled with its filename, followed by the CSS module and any test stub as separate labeled code blocks.

## Pitfalls

- Using defaultProps on a functional component in React 18.3 or later, which logs a deprecation warning on every render.
- Marking a prop isRequired and also giving it a default, which contradicts itself and confuses readers.
- Writing kebab-case class names in the CSS module, which cannot be accessed with dot notation from the styles import.
