React UI Patterns
Table of Contents
Compliance
- Check against current global instructions in
~/.codex/AGENTS.md and linked standards docs.
Overview
Provide concrete, example-driven guidance for React UI composition, state, routing, and component patterns in a TypeScript + Tailwind + Radix stack.
Current baseline markers
- React 19 is the default baseline for hooks, transitions, and client interaction guidance.
- Next.js 16 is the default routing and server/client boundary baseline when the target app uses Next.js.
- Tailwind CSS v4 is the default utility and token baseline for styling examples.
- WCAG 2.2 AA is the default accessibility bar for component and screen recommendations.
Design-system integration
- Apply
frontend/ui/references/design-system-integration-contract.md when giving typography, spacing, iconography, and token guidance.
- Route shared token architecture, aliasing, and theme-governance changes to
design-system.
- Use
frontend/ui/references/skill-routing-matrix-2026.md when prompt scope overlaps with routing (frontend-design) or full UI execution (frontend-ui-design).
Philosophy
- Prefer composable, accessible primitives over bespoke UI logic.
- Keep state local when possible; lift only when needed.
- Preserve repo conventions; do not introduce new patterns without need.
When to use
- Building or refactoring React screens and components.
- Designing layout, routing, or tabbed navigation structures.
- Choosing component-specific patterns or examples in a React stack.
Required inputs
- Target React component(s) or feature description.
- Existing repo conventions, design system, and component references.
- Constraints (router, state library, or data fetching approach).
Deliverables
- Pattern guidance and example structure for the requested UI.
- References to relevant component docs or in-repo examples.
- Notes on accessibility and state ownership where needed.
Quick start
Choose a track based on your goal:
Existing project
- Identify the feature or screen and the primary interaction model (list, detail, editor, settings, tabbed).
- Find a nearby example in the repo with
rg "<ComponentName>" or rg "<RouteName>", then read the closest React component.
- Apply local conventions: prefer React hooks, keep state local when possible, and use context for shared dependencies.
- Choose the relevant component reference from
references/components-index.md and follow its guidance.
- Build the view with small, focused components and predictable data flow.
New project scaffolding
- Start with
references/app-scaffolding-wiring.md to wire Router + Layout + providers.
- Add a minimal route map and layout shell based on the provided skeletons.
- Choose the next component reference based on the UI you need first (Tabs, Dialog, Form, Data table).
- Expand routes and layouts as screens are added.
General rules to follow
- Use idiomatic modern React hooks and state primitives:
useState for local UI state;
useEffectEvent for event logic inside effects when the repo/runtime supports it;
startTransition for non-urgent UI updates;
useDeferredValue for expensive filtered or derived views when user typing should stay responsive.
- Do not add
useMemo or useCallback by default. Use them only when profiling or established repo conventions justify them.
- Prefer composition; keep components small and focused.
- Use async/await for data fetchers and explicit loading/error states.
- Keep server/client boundaries explicit in hybrid React frameworks; do not pull client-only stateful UI into server components accidentally.
- Maintain existing legacy patterns only when editing legacy files.
- Follow the project's formatter and style guide (TypeScript + Tailwind + Biome).
- Avoid adding new dependencies without user approval.
Constraints / Safety
- Redact secrets/PII by default.
- Do not introduce patterns that conflict with the repo's router or state library.
- Preserve behavior; avoid unrequested UI changes.
- Ensure keyboard and screen reader support for interactive components.
Workflow for a new React view
- Define the view's state and its ownership location.
- Identify dependencies to inject via context or props.
- Sketch the component hierarchy and extract repeated parts.
- Decide the async interaction model:
- server-loaded data;
- client fetch with explicit loading/error states;
- optimistic mutation with rollback;
- deferred search/filter rendering.
- Implement async loading with explicit loading/error UI.
- Use transitions or deferred rendering where interaction latency matters.
- Add accessibility labels and roles for interactive elements.
- Validate with a build, story, or targeted UI test and update callsites if needed.
Modern React guidance
- Prefer event handlers and reducers over effect-heavy synchronization.
- Treat
useEffect as an integration boundary for subscriptions, DOM APIs, network lifecycle, or external systems, not as a generic data-flow tool.
- Keep forms explicit about pending, success, and error states.
- For route-level UIs, keep loading and error surfaces close to the route boundary instead of scattering them through child components.
- If the repo is React Compiler-aware, lean on clear code and stable data flow before manual memoization tricks.
Component references
Use references/components-index.md as the entry point. Each component reference should include:
- Intent and best-fit scenarios.
- Minimal usage pattern with local conventions.
- Pitfalls and performance notes.
- Paths to existing examples in the current repo.
Modal patterns
Controlled dialog (preferred)
const [open, setOpen] = useState(false);
<Dialog open={open}
<DialogTrigger asChild>
<Button>Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit item</DialogTitle>
</DialogHeader>
<EditForm => setOpen(false)} />
</DialogContent>
</Dialog>
Dialog owns its actions
- Keep async save state local to dialog content.
- Call
onDone() only after the async action completes successfully.
- Disable action controls while saving to prevent duplicate submits.
Adding a new component reference
- Create
references/<component>.md.
- Keep it short and actionable; link to concrete files in the current repo.
- Update
references/components-index.md with the new entry.
Variation rules
- Vary guidance by screen complexity (simple list vs multi-step flow).
- Prefer minimal scaffolding for small screens.
- Adapt to the repo's styling and routing conventions.
- Choose different async/state patterns for dashboards, forms, editors, and search-heavy screens rather than forcing one template.
Anti-Patterns to Avoid
- Overusing
useEffect for derived state.
- Recreating global state for local component needs.
- Skipping accessibility on interactive elements.
- Adding new dependencies without explicit approval.
- Manually memoizing everything instead of fixing component boundaries or expensive work hotspots.
- Mixing server and client concerns without an explicit boundary.
Example prompts
- "Refactor this settings screen into smaller React components."
- "Design a tabs layout with Radix and Tailwind."
- "Add a dialog pattern for editing an item with a controlled open state."
Remember
The agent is capable of extraordinary work in this domain. These guidelines unlock that potential; they do not constrain it.
Use judgment, adapt to context, and push boundaries when appropriate.
Resources
- Component index:
references/components-index.md
- App wiring:
references/app-scaffolding-wiring.md
Validation
- Run any relevant checks or scripts when available.
- Fail fast and report errors before proceeding.
- Confirm recommended typography, spacing, icon usage, and visual literals stay compliant with
frontend/ui/references/design-system-integration-contract.md.
Anti-patterns
- Avoid vague guidance without concrete steps.
- Do not invent results or commands.
Procedure
- Clarify scope and inputs.
- Execute the core workflow.
- Summarize outputs and next steps.
Antipatterns
- Do not add features outside the agreed scope.
Philosophy and tradeoffs
- Use this skill when consistent decision-making matters more than one-off execution because project context should drive the approach.
- Principle and mindset: prioritize tradeoffs and constraints over rigid checklists; understand why each step exists.
- Ask this to keep outcomes robust: Why is this the right default, and what could change this outcome?
- How do we adapt if constraints shift?
- What evidence is needed before choosing one path over another?
Anti-patterns and caveats
- Avoid applying this playbook generically without checking repository-specific context.
- NEVER skip required validation gates when behavior changes.
- DO NOT use this skill as a rigid replacement for engineering judgment.
- DON'T ignore warnings or assume one pattern fits all repos.
- Common pitfall: treating anti-patterns as optional.
- Incorrect assumptions here can lead to fragile guidance.
- Warning: wrong sequencing can create avoidable regressions.
Variation and adaptation
- Vary the workflow by team size, risk, and deployment target.
- Use different strategies for small, medium, and large changes.
- Adapt recommendations to the specific environment and avoid repetitive templates.
- Avoid generic or cookie-cutter responses; craft context-specific alternatives.
- Keep outputs diverse and not repetitive.
- Converge on a custom path only after evidence review.
- Different constraints should produce different, non-generic recommendations.
Empowering execution style
- Be capable of exploring multiple options and enabling the team to make safe decisions.
- Unlock confidence by explaining options and tradeoffs clearly.
- Feel free to be creative while staying rigorous and precise.
- Push boundaries with practical alternatives when simple recipes fail.
- Enable outcomes-oriented problem solving.
See Also
| Skill |
When to use together |
| [[frontend-ui-design]] |
Apply React patterns to components being designed |
| [[design-system]] |
Keep typography, spacing, and icon guidance aligned to canonical token governance |
| [[shadcn-ui]] |
Source Radix/shadcn primitives for React pattern implementations |
| [[stitch-react-components]] |
Use patterns when converting Stitch screens to React |
| [[baseline-ui]] |
Validate React component patterns against baseline rules |
| [[ui-ux-creative-coding]] |
Layer motion on top of React pattern scaffolds |
Topic map: [[frontend-ui]]
Decision feedback protocol (required):
- If post-run feedback capture is enabled for this runtime, emit a non-blocking
post_run_feedback event via request_user_input after result delivery.
- Capture:
decision (accepted|partial|rejected|deferred), outcome (good|neutral|bad|unknown), and confidence (high|medium|low).
- Persist with:
python3 utilities/skill-builder/scripts/record_skill_feedback.py --skill-path <path/to/SKILL.md> --decision <...> --outcome <...> --confidence <...> --notes "...".
- The recorder tags
subject (for example ui, code_review, backend, security) for cross-domain quality analytics.
Gotchas
- None yet. Capture recurring failures here as symptom -> cause -> do instead -> check.
Failure mode
- If the React architecture problem, routing/state constraints, or component boundaries are unclear, stop, report the ambiguity, and fall back to a smaller composition recommendation instead of forcing a broad pattern.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: react-ui-patterns3description: Provide concrete React UI composition patterns for TypeScript + Tailwind + Radix, including state, routing, and component structure examples. Use when building or refactoring React screens and components for maintainability. Use when this capability is needed.4---56# React UI Patterns78## Table of Contents9- [Overview](#overview)10- [Current baseline markers](#current-baseline-markers)11- [Design-system integration](#design-system-integration)12- [Philosophy](#philosophy)13- [Scope and triggers](#scope-and-triggers)14- [Required inputs](#required-inputs)15- [Deliverables](#deliverables)16- [Quick start](#quick-start)17- [General rules to follow](#general-rules-to-follow)18- [Constraints / Safety](#constraints--safety)19- [Workflow for a new React view](#workflow-for-a-new-react-view)20- [Modern React guidance](#modern-react-guidance)21- [Component references](#component-references)22- [Modal patterns](#modal-patterns)23- [Adding a new component reference](#adding-a-new-component-reference)24- [Variation rules](#variation-rules)25- [Anti-Patterns to Avoid](#anti-patterns-to-avoid)26- [Example prompts](#example-prompts)27- [Resources](#resources)28- [Validation](#validation)29- [Anti-patterns](#anti-patterns)30- [Procedure](#procedure)31- [Antipatterns](#antipatterns)3233## Compliance34- Check against current global instructions in `~/.codex/AGENTS.md` and linked standards docs.3536## Overview37Provide concrete, example-driven guidance for React UI composition, state, routing, and component patterns in a TypeScript + Tailwind + Radix stack.3839## Current baseline markers40- React 19 is the default baseline for hooks, transitions, and client interaction guidance.41- Next.js 16 is the default routing and server/client boundary baseline when the target app uses Next.js.42- Tailwind CSS v4 is the default utility and token baseline for styling examples.43- WCAG 2.2 AA is the default accessibility bar for component and screen recommendations.4445## Design-system integration46- Apply `frontend/ui/references/design-system-integration-contract.md` when giving typography, spacing, iconography, and token guidance.47- Route shared token architecture, aliasing, and theme-governance changes to `design-system`.48- Use `frontend/ui/references/skill-routing-matrix-2026.md` when prompt scope overlaps with routing (`frontend-design`) or full UI execution (`frontend-ui-design`).4950## Philosophy51- Prefer composable, accessible primitives over bespoke UI logic.52- Keep state local when possible; lift only when needed.53- Preserve repo conventions; do not introduce new patterns without need.5455## When to use56- Building or refactoring React screens and components.57- Designing layout, routing, or tabbed navigation structures.58- Choosing component-specific patterns or examples in a React stack.5960## Required inputs61- Target React component(s) or feature description.62- Existing repo conventions, design system, and component references.63- Constraints (router, state library, or data fetching approach).6465## Deliverables66- Pattern guidance and example structure for the requested UI.67- References to relevant component docs or in-repo examples.68- Notes on accessibility and state ownership where needed.6970## Quick start7172Choose a track based on your goal:7374### Existing project7576- Identify the feature or screen and the primary interaction model (list, detail, editor, settings, tabbed).77- Find a nearby example in the repo with `rg "<ComponentName>"` or `rg "<RouteName>"`, then read the closest React component.78- Apply local conventions: prefer React hooks, keep state local when possible, and use context for shared dependencies.79- Choose the relevant component reference from `references/components-index.md` and follow its guidance.80- Build the view with small, focused components and predictable data flow.8182### New project scaffolding8384- Start with `references/app-scaffolding-wiring.md` to wire Router + Layout + providers.85- Add a minimal route map and layout shell based on the provided skeletons.86- Choose the next component reference based on the UI you need first (Tabs, Dialog, Form, Data table).87- Expand routes and layouts as screens are added.8889## General rules to follow9091- Use idiomatic modern React hooks and state primitives:92 - `useState` for local UI state;93 - `useEffectEvent` for event logic inside effects when the repo/runtime supports it;94 - `startTransition` for non-urgent UI updates;95 - `useDeferredValue` for expensive filtered or derived views when user typing should stay responsive.96- Do not add `useMemo` or `useCallback` by default. Use them only when profiling or established repo conventions justify them.97- Prefer composition; keep components small and focused.98- Use async/await for data fetchers and explicit loading/error states.99- Keep server/client boundaries explicit in hybrid React frameworks; do not pull client-only stateful UI into server components accidentally.100- Maintain existing legacy patterns only when editing legacy files.101- Follow the project's formatter and style guide (TypeScript + Tailwind + Biome).102- Avoid adding new dependencies without user approval.103104## Constraints / Safety105- Redact secrets/PII by default.106- Do not introduce patterns that conflict with the repo's router or state library.107- Preserve behavior; avoid unrequested UI changes.108- Ensure keyboard and screen reader support for interactive components.109110## Workflow for a new React view1111121. Define the view's state and its ownership location.1132. Identify dependencies to inject via context or props.1143. Sketch the component hierarchy and extract repeated parts.1154. Decide the async interaction model:116 - server-loaded data;117 - client fetch with explicit loading/error states;118 - optimistic mutation with rollback;119 - deferred search/filter rendering.1205. Implement async loading with explicit loading/error UI.1216. Use transitions or deferred rendering where interaction latency matters.1227. Add accessibility labels and roles for interactive elements.1238. Validate with a build, story, or targeted UI test and update callsites if needed.124125## Modern React guidance126127- Prefer event handlers and reducers over effect-heavy synchronization.128- Treat `useEffect` as an integration boundary for subscriptions, DOM APIs, network lifecycle, or external systems, not as a generic data-flow tool.129- Keep forms explicit about pending, success, and error states.130- For route-level UIs, keep loading and error surfaces close to the route boundary instead of scattering them through child components.131- If the repo is React Compiler-aware, lean on clear code and stable data flow before manual memoization tricks.132133## Component references134135Use `references/components-index.md` as the entry point. Each component reference should include:136- Intent and best-fit scenarios.137- Minimal usage pattern with local conventions.138- Pitfalls and performance notes.139- Paths to existing examples in the current repo.140141## Modal patterns142143### Controlled dialog (preferred)144145```tsx146const [open, setOpen] = useState(false);147148<Dialog open={open} onOpenChange={setOpen}>149 <DialogTrigger asChild>150 <Button>Open</Button>151 </DialogTrigger>152 <DialogContent>153 <DialogHeader>154 <DialogTitle>Edit item</DialogTitle>155 </DialogHeader>156 <EditForm onDone={() => setOpen(false)} />157 </DialogContent>158</Dialog>159```160161### Dialog owns its actions162163- Keep async save state local to dialog content.164- Call `onDone()` only after the async action completes successfully.165- Disable action controls while saving to prevent duplicate submits.166167## Adding a new component reference168169- Create `references/<component>.md`.170- Keep it short and actionable; link to concrete files in the current repo.171- Update `references/components-index.md` with the new entry.172173## Variation rules174- Vary guidance by screen complexity (simple list vs multi-step flow).175- Prefer minimal scaffolding for small screens.176- Adapt to the repo's styling and routing conventions.177- Choose different async/state patterns for dashboards, forms, editors, and search-heavy screens rather than forcing one template.178179## Anti-Patterns to Avoid180- Overusing `useEffect` for derived state.181- Recreating global state for local component needs.182- Skipping accessibility on interactive elements.183- Adding new dependencies without explicit approval.184- Manually memoizing everything instead of fixing component boundaries or expensive work hotspots.185- Mixing server and client concerns without an explicit boundary.186187## Example prompts188- "Refactor this settings screen into smaller React components."189- "Design a tabs layout with Radix and Tailwind."190- "Add a dialog pattern for editing an item with a controlled open state."191192## Remember193194The agent is capable of extraordinary work in this domain. These guidelines unlock that potential; they do not constrain it.195Use judgment, adapt to context, and push boundaries when appropriate.196197## Resources198- Component index: `references/components-index.md`199- App wiring: `references/app-scaffolding-wiring.md`200201## Validation202- Run any relevant checks or scripts when available.203- Fail fast and report errors before proceeding.204- Confirm recommended typography, spacing, icon usage, and visual literals stay compliant with `frontend/ui/references/design-system-integration-contract.md`.205206## Anti-patterns207- Avoid vague guidance without concrete steps.208- Do not invent results or commands.209210## Procedure2111) Clarify scope and inputs.2122) Execute the core workflow.2133) Summarize outputs and next steps.214215## Antipatterns216- Do not add features outside the agreed scope.217218<!-- skill-score-boost-v1 -->219## Philosophy and tradeoffs220- Use this skill when consistent decision-making matters more than one-off execution because project context should drive the approach.221- Principle and mindset: prioritize tradeoffs and constraints over rigid checklists; understand why each step exists.222- Ask this to keep outcomes robust: Why is this the right default, and what could change this outcome?223- How do we adapt if constraints shift?224- What evidence is needed before choosing one path over another?225226## Anti-patterns and caveats227- Avoid applying this playbook generically without checking repository-specific context.228- **NEVER** skip required validation gates when behavior changes.229- **DO NOT** use this skill as a rigid replacement for engineering judgment.230- **DON'T** ignore warnings or assume one pattern fits all repos.231- Common pitfall: treating anti-patterns as optional.232- Incorrect assumptions here can lead to fragile guidance.233- Warning: wrong sequencing can create avoidable regressions.234235## Variation and adaptation236- Vary the workflow by team size, risk, and deployment target.237- Use different strategies for small, medium, and large changes.238- Adapt recommendations to the specific environment and avoid repetitive templates.239- Avoid generic or cookie-cutter responses; craft context-specific alternatives.240- Keep outputs diverse and not repetitive.241- Converge on a custom path only after evidence review.242- Different constraints should produce different, non-generic recommendations.243244## Empowering execution style245- Be capable of exploring multiple options and enabling the team to make safe decisions.246- Unlock confidence by explaining options and tradeoffs clearly.247- Feel free to be creative while staying rigorous and precise.248- Push boundaries with practical alternatives when simple recipes fail.249- Enable outcomes-oriented problem solving.250251## See Also252253| Skill | When to use together |254|---|---|255| [[frontend-ui-design]] | Apply React patterns to components being designed |256| [[design-system]] | Keep typography, spacing, and icon guidance aligned to canonical token governance |257| [[shadcn-ui]] | Source Radix/shadcn primitives for React pattern implementations |258| [[stitch-react-components]] | Use patterns when converting Stitch screens to React |259| [[baseline-ui]] | Validate React component patterns against baseline rules |260| [[ui-ux-creative-coding]] | Layer motion on top of React pattern scaffolds |261262**Topic map:** [[frontend-ui]]263264<!-- decision-feedback-protocol:v2 -->265**Decision feedback protocol (required):**266- If post-run feedback capture is enabled for this runtime, emit a non-blocking `post_run_feedback` event via `request_user_input` after result delivery.267- Capture: `decision` (`accepted|partial|rejected|deferred`), `outcome` (`good|neutral|bad|unknown`), and `confidence` (`high|medium|low`).268- Persist with: `python3 utilities/skill-builder/scripts/record_skill_feedback.py --skill-path <path/to/SKILL.md> --decision <...> --outcome <...> --confidence <...> --notes "..."`.269- The recorder tags `subject` (for example `ui`, `code_review`, `backend`, `security`) for cross-domain quality analytics.270<!-- /decision-feedback-protocol -->271272## Gotchas273- None yet. Capture recurring failures here as symptom -> cause -> do instead -> check.274275## Failure mode276- If the React architecture problem, routing/state constraints, or component boundaries are unclear, stop, report the ambiguity, and fall back to a smaller composition recommendation instead of forcing a broad pattern.277278---279> Converted and distributed by [TomeVault](https://tomevault.io/claim/jscraik) — claim your Tome and manage your conversions.280<!-- tomevault:4.0:skill_md:2026-04-13 -->