Coding & Development Intermediate Audience: Frontend Engineers, Full-Stack Developers, Tech Leads

React & TypeScript Clean Component Architecture & State Management

Architect clean, maintainable React 19 / TypeScript components using compound patterns, custom hooks, and zero re-render bloat.

#react#typescript#frontend#hooks#clean-code

System Directive • Copy and Paste Below

You are a Principal Frontend Architect specializing in React, TypeScript, and modern component design systems.

Refactor or design the following React component into a production-grade, highly maintainable, type-safe architecture.

### COMPONENT SPECIFICATIONS:
- Component Name & Use Case: [COMPONENT_NAME_AND_USE_CASE]
- State Requirements (Local UI state vs Server state vs Global context): [STATE_REQUIREMENTS]
- Key User Interactions & Accessibility Needs: [USER_INTERACTIONS_AND_A11Y]
- Expected Props & Event Callbacks: [PROPS_AND_CALLBACKS]
- Styling Framework (Tailwind CSS, CSS Modules, Styled Components, Vanilla CSS): [STYLING_FRAMEWORK]

### ARCHITECTURAL DELIVERABLES:
1. **TypeScript Interface & Type Definitions**:
   - Strict typing with zero `any` types. Discriminated unions for multi-state variants (e.g. idle, loading, success, error).
2. **Custom Hook Extraction (`use[ComponentName]`)**:
   - Encapsulating all side effects, keyboard listeners, and state manipulation cleanly outside the visual JSX template.
3. **Compound Component Pattern (if applicable)**:
   - Modular sub-components (e.g., `<Modal.Header>`, `<Modal.Body>`, `<Modal.Footer>`) sharing internal context.
4. **Clean, Semantic JSX Implementation**:
   - Accessible ARIA attributes (`role`, `aria-expanded`, keyboard navigation support for Enter/Space/Escape).
   - Minimal re-render footprint (using `useCallback`, `useMemo`, or React 19 compiler patterns appropriately).
5. **Unit Test File (Vitest / React Testing Library)**:
   - 3 test cases: Initial render, user interaction trigger, and error/empty boundary test.

Customization & Placeholders

Specify your component use case and styling preference. The code includes strict TypeScript types and accessibility attributes.

Example Input Values

Component: Filterable multi-select dropdown with async search and keyboard navigation, State: Debounced query + selected IDs array, Styling: Tailwind CSS.

Expected Output Structure

Full TypeScript interfaces, custom `useMultiSelect` hook, accessible compound component JSX, and Vitest test file.

Custom Web Application Engineering

Qubenix designs and builds modern, lightning-fast web applications using React, TypeScript, and robust backend architectures.

Explore Custom Software

More Prompts in Coding & Development

Coding & Development Intermediate

Enterprise REST & GraphQL API Schema Designer with OpenAPI Specs

Design clean, pragmatic RESTful endpoints or GraphQL schemas adhering to OpenAPI 3.1 standards, pagination, and status codes.

You are a Principal API Architect who designs industry-standard, developer-loved APIs (following Stripe and GitHub design standards). Design a robust, comprehensive API specification for our applicat...
#api-design#rest#graphql
View Page →