Agent skill
react-compound-components
React compound components pattern (safe, minimal context, ergonomic API)
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/react-compound-components-oalkabouss-fullstack-agent-skil-2
Metadata
Additional technical details for this skill
- stack
- node-react-next
- style
- solid-clean-code
SKILL.md
What I do
Je fournis un guide pour implémenter des Compound Components sûrs :
- contexte minimal
- API ergonomique
- erreurs explicites
Minimal template
type Ctx = { id: string };
const Ctx = createContext<Ctx | null>(null);
export function Root({ id, children }: { id: string; children: ReactNode }) {
return <Ctx.Provider value={{ id }}>{children}</Ctx.Provider>;
}
Root.Label = function Label({ children }: { children: ReactNode }) {
const ctx = useContext(Ctx);
if (!ctx) throw new Error('Root.Label must be used within Root');
return <label htmlFor={ctx.id}>{children}</label>;
};
Example
// ui/form/FormField.tsx
import React, { createContext, useContext } from "react";
type Ctx = { id: string };
const FieldCtx = createContext<Ctx | null>(null);
export function FormField({ id, children }: { id: string; children: React.ReactNode }) {
return <FieldCtx.Provider value={{ id }}>{children}</FieldCtx.Provider>;
}
FormField.Label = function Label({ children }: { children: React.ReactNode }) {
const ctx = useContext(FieldCtx);
if (!ctx) throw new Error("FormField.Label must be used within FormField");
return <label htmlFor={ctx.id} className="text-sm font-medium">{children}</label>;
};
FormField.Input = function Input(props: React.InputHTMLAttributes<HTMLInputElement>) {
const ctx = useContext(FieldCtx);
if (!ctx) throw new Error("FormField.Input must be used within FormField");
return <input id={ctx.id} {...props} className="w-full rounded-md border p-2" />;
};
Utilisation :
<FormField id="email">
<FormField.Label>Email</FormField.Label>
<FormField.Input type="email" />
</FormField>
When NOT to use
- Si l'état partagé devient complexe : passer à props explicites + hook.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?