react-component
FreeNo executable scriptsNot checkedUse when creating UI components in React - functional components, hooks, custom hooks, or component composition patterns. NOT when backend logic, API routes…
by aiskillstore★ 509 GitHub starsAbout this skill
React Component Skill
Overview
Expert guidance for building React functional components, hooks, and composition patterns. Focuses on TypeScript, performance, accessibility, and modern React best practices.
When This Skill Applies
This skill triggers when users request:
- UI Components: "Create a student KPI card", "Build a modal", "Form component"
- Hooks: "Custom attendance hook", "useContext for theme", "useState for data"
- Patterns: "Component composition", "HOC", "render props"
- ERP Widgets: KPI cards, forms, data tables, dashboards
Core Rules
1. Functional Components Always
// ✅ GOOD: Functional component with TypeScript
interface StudentKPICardProps {
studentName: string;
attendance: number;
loading?: boolean;
}
export const StudentKPICard = React.memo(({ studentName, attendance, loading = false }: StudentKPICardProps) => {
const [isHovered, setIsHovered] = useState(false);
if (loading) return <LoadingSkeleton />;
return <div>{/* content */}</div>;
});
Requirements:
- Always use functional components (no class components)
- Type all props interfaces explicitly
- Use
React.memofor components receiving same props frequently - Use
React.forwardRefwhen ref forwarding is needed
2. Hooks Usage
// ✅ GOOD: Proper hook usage with cleanup
export const AttendanceMonitor = ({ studentId }: { studentId: string }) => {
const [data, setData] = useState(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let isMounted = true;
const fetchAttendance = async () => {
try {
const result = await api.getAttendance(studentId);
if (isMounted) setData(result);
} catch (err) {
if (isMounted) setError(err.message);
}
};
fetchAttendance();
return () => {
isMounted = false;
};
}, [studentId]);
return /* JSX */;
};
Requirements:
useState: For local component state onlyuseEffect: For side-effects with proper cleanup functionsuseContext: For global state (theme, auth, language)- Always include all dependencies in dependency array
- Use
useCallback/useMemofor expensive operations in lists
3. Custom Hooks
// ✅ GOOD: Custom hook with proper types
interface UseAttendanceResult {
data: AttendanceData | null;
loading: boolean;
error: string | null;
refetch: () => Promise<void>;
}
export const useAttendance = (studentId: string): UseAttendanceResult => {
const [data, setData] = useState<AttendanceData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchAttendance = useCallback(async () => {
setLoading(true);
try {
const result = await api.getAttendance(studentId);
setData(result);
setError(null);
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
}, [studentId]);
useEffect(() => {
fetchAttendance();
}, [fetchAttendance]);
return { data, loading, error, refetch: fetchAttendance };
};
Requirements:
- All custom hooks must start with
useprefix - Extract reusable logic into hooks
- Return typed interfaces for hook results
- Include loading, error states, and retry mechanisms
- Keep hooks focused on single responsibility
4. Component Composition
// ✅ GOOD: Composition via children prop
interface CardProps {
title: string;
children: React.ReactNode;
footer?: React.ReactNode;
}
export const Card = ({ title, children, footer }: CardProps) => (
<div className="card">
<h2>{title}</h2>
<div className="card-content">{children}</div>
{footer && <div className="card-footer">{footer}</div>}
</div>
);
// Usage
<Card title="Student Info" footer={<Button>Save</Button>}>
<StudentDetails />
</Card>
// ✅ GOOD: Higher-order component pattern
export const withLoading = <P extends object>(WrappedComponent: React.ComponentType<P>) => {
return (props: P & { loading?: boolean }) => {
const { loading = false, ...rest } = props;
if (loading) return <LoadingSpinner />;
return <WrappedComponent {...(rest as P)} />;
};
};
Requirements:
- Prefer composition over inheritance
- Use
childrenprop for flexible content - Use render props when component needs to share data
- Use HOCs sparingly and with proper TypeScript types
- Keep components small and focused (single responsibility)
Output Requirements
Code Files
Component file (
ComponentName.tsx):- Functional component with typed props
- Hooks applied correctly
- Exported as named export
- Default export when appropriate
Test file (
ComponentName.test.tsx):- Jest/Vitest + React Testing Library
- Test component renders with props
- Test user interactions
- Test loading/error states
- Accessibility tests
Storybook file (`ComponentName.storie
Install react-component in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the react-component skill do?
Use when creating UI components in React - functional components, hooks, custom hooks, or component composition patterns. NOT when backend logic, API routes, or non-React frameworks are involved. Triggers: "create component", "build widget", "KPI card", "form", "modal", "custom hook", "useContext", "useState", "useEffect".
How do I install the react-component skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the react-component skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic