Prop & State Schema Designer (Reusable Component Contracts)
Define clean, minimal prop/state contracts and events so components are reusable and testable from day one.
Prompt Overview
Tips For You
- Keep variants enumerable; avoid free-form strings. - Name events consistently: onAction, onDismiss, onChange. - Default props must reflect the screenshot’s baseline state.
From Operations TeamNexusAi TechnologyProblem It Solves
Prevents brittle APIs and over-parameterized components by aligning props with real variants and data flows.
API clarity
Produces lean, type-safe prop/event contracts.
State placement
Explains where state should live and why.
Variant discipline
Encourages finite, testable variants.
Test scaffolds
Ships with coverage ideas per component.
AI Prompt Instructions
Act as: A React lead focused on reusable APIs and clean state isolation.
Why this task matters: Most rework happens when a component’s API doesn’t match real variants. A crisp contract unlocks reuse and easier tests.
Important boundaries:
- Prefer controlled props with explicit onChange handlers.
- Keep state local only for UI transient concerns (open/closed, hover, input draft).
- Avoid prop drilling when a slot or context is cleaner.
User inputs:
- Component list and purposes (from your layout plan)
- Data sources and events (clicks, selects, form submits)
- Known variants (size, color, density, emphasis)
Objectives:
1) For each component, define props (type, purpose, default) and events.
2) Recommend state location (local vs. parent vs. global store).
3) Identify sensible variants and token hooks.
4) Provide test cases per component API.
Analysis workflow:
1) Map screenshot variability to variants rather than boolean explosion.
2) Propose type-safe props and event names.
3) Note accessibility needs tied to props (aria-label, describedby IDs).
4) Draft Jest/RTL test ideas for key states.
Required output format:
- ComponentAPI: for each component → props, events, variants
- StatePlan: who owns which state and why
- Tests: minimal test matrix suggestions
- Risks: uncertain API edges to confirm
Quality controls:
- No duplicated responsibilities across props.
- Event names are verb-first and consistent.
Verification checklist:
- Can a junior dev implement using only this contract?
- Do tests cover failure and empty states?
Final instruction: Deliver ComponentAPI, StatePlan, Tests, and Risks with concise tables or bullet lists, ready for code generation.
Expected Outcome
ComponentAPI: - StatsCard: props {title, value, delta?, icon?, variant: "neutral"|"success"|"alert"}; events {} - DataTable: props {rows, columns, page, pageSize}; events {onPageChange, onSort} StatePlan: - Pagination lives in parent; sorting lives in parent. Tests: - Renders variants; truncates long titles; calls onSort with key+dir.
Implementation Journey
Generate API draft in ChatGPT
Paste your component list, interactions, and variants into ChatGPT. Ask for ComponentAPI, StatePlan, Tests, and Risks. Expect minimal, type-safe prop sets with clear event contracts.
12 minCreate TypeScript interfaces
In your editor, convert the proposed props/events into TypeScript interfaces and add TODOs for any Risks items. Wire them into component stubs and Storybook stories.
20 minValidate with a test matrix
Use Jest/RTL to implement the Tests section quickly. Ensure baseline, variant, and empty/error states are covered before writing UI logic.
20 min
