Agent skill Frontend
React Composition Patterns
Build reusable component APIs with compound components, shared state and explicit variants instead of growing boolean props.
Install the skill
Run the command from your project root with Node.js and npm.
npx skills@latest add vercel-labs/agent-skills --skill vercel-composition-patterns --agent claude-code --yesCheck this file in your project.claude/skills/vercel-composition-patterns/SKILL.md
Other ways to install
Choose an assistant interactively
npx skills@latest add vercel-labs/agent-skills --skill vercel-composition-patternsSelect your assistant and choose the project installation scope.
Official instructions
The tested Skills CLI 1.10.0 requires Node.js 22.20 or later. Open your React project in an assistant that can load the Skill. Have the component, its callers, and existing tests or stories available. Check which React versions the project supports before using the React 19 examples.
View operation manualWhat this skill helps with
- Replace growing boolean prop combinations with explicit variants.
- Design compound components with shared context.
- Clarify component APIs and state ownership.
Good for
- Reusable component libraries
- Components with many configuration variants
- Installed skill name
- vercel-composition-patterns
- Official rule files
- The rules/ directory covers architecture, state management, implementation patterns, and React 19 APIs.
- What to bring
- A shared component, representative call sites, and the interactions they rely on.
- Deliverable
- A component API with clear variants and state ownership, plus check results for existing callers.
- Skill name
vercel-composition-patterns- Repository
vercel-labs/agent-skills
Check what callers rely on before changing the API
A request without a baseline
Use vercel-composition-patterns to remove the boolean props from our shared modal.
The same flag can select a whole flow or represent a current state. Changing both at once can break defaults, callbacks, or keyboard behavior that callers rely on.
A refactor you can verify
- Map the prop combinations each caller actually uses and record their behavior.
- Compose named variants where workflows differ and keep state such as open or disabled explicit.
- Migrate one caller at a time and re-run the checks for the original interactions.
React Composition Patterns operation manual
Refactor a shared modal whose flags select different workflows, or give a filter sidebar and toolbar a shared source of state. Use the project’s existing UI primitives and verify each change through real callers.
Use an edit-project dialog and a delete confirmation to find which parts can be shared and which belong to a named variant.
Map the callers and record the baseline
Find the imports, wrappers, and tests for the shared modal. Record the modes people use and what happens when each opens, submits, fails, or closes.
- List mode selectors such as isEditing separately from state such as open and isSubmitting.
- Capture which caller owns open state, which callbacks fire, and where focus returns on close.
Prompt · Step 1Use the installed vercel-composition-patterns skill to inspect my shared React modal. Start with architecture-avoid-boolean-props. Look for a modal used for editing a project and confirming its deletion, or ask me for the component path if the target is unclear. Read its implementation, exports, call sites, and existing tests or stories. Identify the supported React versions from the app or library configuration. For each real prop combination, report the caller, whether it controls open state, what opens and closes the modal, which callbacks fire on success or failure, and what happens to focus. Identify which props select a workflow and which represent state. Run relevant existing checks if available to establish a baseline, and report any behavior you could only infer from source. Keep this pass to inspection.Sketch named variants around shared parts
Give each workflow a recognizable entry point. Share the existing dialog primitive and compose the title, content, and actions where the caller needs to arrange them.
- Each named variant shows the intent at its call site.
- The current dialog primitive still handles the interaction behavior it owns.
- Every existing caller has a migration or compatibility path.
Prompt · Step 2Use vercel-composition-patterns and the modal caller inventory to propose a small API. If the inventory is missing, rebuild it from the current export and its real call sites. Ask for the modal path if you cannot identify it. Read architecture-compound-components and patterns-explicit-variants. Sketch edit and delete variants using the current dialog primitive, and show one before-and-after call site for each. Decide which parts callers need to compose and which stay internal. Keep action labels, confirmation requirements, controlled open behavior, and callback semantics tied to the inventory. Show who owns loading and error state. Identify compatibility needs for the existing export, including callers that cannot migrate in the same change. Provide the proposed signatures and the first caller to migrate. Keep this pass to the design.Implement the API and migrate one caller
Build the shared pieces and move one real caller first. Keep the existing export available for callers still using it.
Prompt · Step 3Use vercel-composition-patterns to implement the agreed modal API in my project and migrate the first identified caller. If the API or caller is unclear, ask for that specific detail. Reuse the current dialog, form, and action components. Keep the existing export compatible wherever it still has callers. Preserve controlled or uncontrolled open behavior, validation, failure and retry behavior, and callback timing as observed in the baseline. Use the project’s supported React APIs. Run the existing type check and the targeted tests for the changed components when available. Report the files and caller migrated, the remaining callers, and the actual check results.Verify the migrated and legacy callers
Compare both paths with the baseline before migrating more callers. Test with safe local data when a workflow performs a destructive action.
- Both caller APIs behave as expected in their real entry points.
- Validation and failed requests leave the dialog in the expected state.
- Keyboard dismissal and focus return match the original behavior.
Prompt · Step 4Use vercel-composition-patterns to review the modal change against the original caller inventory. If the baseline is missing, recover the original behavior from the prior revision or ask me for the expected behavior and the two call sites. Mark any baseline you cannot recover as unverified. Run the existing targeted tests and open the migrated call site and a remaining legacy caller in a local or test environment if available. With disposable test data, check opening, the existing keyboard dismissal policy, focus return, cancellation, and the expected success and error paths. Verify that a pending action follows the baseline duplicate-submit and closing behavior. Report the caller and evidence for each check. If you could only inspect some behavior in source, name the checks that still need a running app. Identify any regression before proceeding with the next caller.
Find the right composition rule
Point the assistant to the named file in the installed Skill’s rules/ directory and give it a real call site to inspect.
Several flags select the modal workflowVariants
- Command or reference
patterns-explicit-variants- Examples
- Compare the edit and delete call sites. Sketch named components around their actual differences.
A caller needs to arrange the dialog’s partsArchitecture
- Command or reference
architecture-compound-components- Examples
- Find which title, body, and actions callers already compose and which parts need shared dialog state.
Sibling controls need the same filter valuesState
- Command or reference
state-lift-state- Examples
- Locate the nearest shared owner of the sidebar and toolbar. Trace a change from control to results.
A UI slot is passed through a render callbackComposition
- Command or reference
patterns-children-over-render-props- Examples
- Try children for a footer the caller can supply directly. Check if a callback receives internal data before replacing it.
An example uses ref as a prop or reads context with use()React 19
- Command or reference
react19-no-forwardref- Examples
- Check every supported React version before applying the example. Choose ref and context APIs that work across that range.
React Composition Patterns troubleshooting
How do I make sure the assistant loaded the right Skill?
Open the project where you installed it, mention vercel-composition-patterns, and ask the assistant to identify its installed SKILL.md and the rule file it used. If your client has not discovered the installation, try opening a new session in that project.
Which boolean props should I keep?
Keep props such as open, disabled, or isSubmitting when they express real state with a clear contract. When several flags combine to select different layouts or actions, map the combinations callers use and consider named variants. Preserve existing defaults and callbacks during migration.
Can I follow the guide in a React 18 project?
Yes. Compound components, children, explicit variants, and shared state work with React 18. Keep React 18-compatible APIs such as useContext and forwardRef where needed. The separate React 19 rule and examples using the newer context or ref syntax require React 19 or later.