---
name: react-component-validator
description: "A pass or fail report on one React component: syntax slips, missing or mismatched PropTypes, deprecated APIs, and whether it runs on your React version, with a JSON summary a script can read. Use when a React component should be checked for syntax errors, missing or wrong PropTypes, deprecated APIs, and compatibility with a specific React version before it is merged. Do not use for performance profiling, accessibility audits, or rewriting the component. Related topics: coding, react."
---

# React Component Validator

A pass or fail report on one React component: syntax slips, missing or mismatched PropTypes, deprecated APIs, and whether it runs on your React version, with a JSON summary a script can read.

## When to use

Use this skill when a React component should be checked for syntax errors, missing or wrong PropTypes, deprecated APIs, and compatibility with a specific React version before it is merged. Do not use it for performance profiling, accessibility audits, or rewriting the component.

## 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. Scan for syntax and rule-of-hooks errors first, since any of those stops the component from running at all.
3. Diff the props the code reads against the expected prop types and list each missing, unused, or mismatched prop with its line.
4. Check each React API in the code against the selected version and name anything deprecated or removed there.
5. In Strict mode, add missing keys, inline object props, and effects without cleanup to the report.
6. Fill the summary JSON with counts that match the bullets, and set compatible to true only when no version issue was found.

## Inputs

- **Component name** (free text, e.g. "MyComponent")
- **Component code** (longer free text)
- **Expected prop types** (choose any: string, number, object, array, bool, func)
- **React version** (choose one: 16.8, 17.0, 18.0, 18.2, 19.0)
- **Strictness** (choose one: Loose, Strict)
- **Include test coverage notes** (choose one: Yes, No)

## Output

A Validation Report section with one bullet per issue (line, severity, fix), followed by a JSON object named summary with errors, warnings, missingPropTypes, and compatible.

## Prompt template

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

### React Component Validation

Validate this React component.

- Component name: {{Component name}}
- Component code: {{Component code}}
- Expected prop types: {{Expected prop types}}
- React version: {{React version}}
- Strictness: {{Strictness}}
- Include test coverage notes: {{Include test coverage notes}}

Read the code as a compiler would first: unbalanced JSX, a missing return, hooks called inside conditions or loops, an undefined identifier. Then compare the props the code reads against the expected prop types and report each prop that is read but not declared, declared but never read, or declared with a different type. Check every API the component uses against the chosen React version, naming anything deprecated or removed (legacy context, string refs, componentWillMount, ReactDOM.render on 18 and later, defaultProps on function components on 19). In Strict mode also flag missing keys, inline object props that defeat memoisation, and effects without cleanup. When coverage notes are requested, list the behaviours a test should cover. Cite the line for every issue.

Return a markdown section titled Validation Report with one bullet per issue (line, severity, what to change), then a JSON object named summary with the keys errors, warnings, missingPropTypes, and compatible. When there are no issues, say the component passes all checks.

## Pitfalls

- Reporting a hook as misused because it sits inside a custom hook, which is allowed.
- Flagging defaultProps as deprecated on React 17, where it is fine; the warning only applies to function components on 18.3 and later.
- Leaving summary counts that disagree with the bullet list, so the script reading the JSON trusts the wrong number.
