react
When to use this skill
Use this skill whenever the user wants to:
- Build user interfaces with React components and JSX
- Manage component state and lifecycle with hooks
- Create reusable, composable React components
- Use Context API or state management libraries (Redux, Zustand)
- Set up React projects with Vite or Create React App
- Implement routing with React Router
- Optimize rendering performance (React.memo, useMemo, lazy loading)
How to use this skill
Workflow
- Identify the request area (component creation, state management, routing, performance, etc.)
- Apply React best practices following the official documentation patterns
- Generate JSX/TSX code using functional components and hooks
- Verify the component tree renders correctly and state flows are clean
1. Functional Component
import { useState } from 'react';
interface UserCardProps {
name: string;
email: string;
onSelect: (name: string) => void;
}
export function UserCard({ name, email, onSelect }: UserCardProps) {
return (
<div className="user-card" onClick={() => onSelect(name)}>
<h3>{name}</h3>
<p>{email}</p>
</div>
);
}
2. State and Effects
import { useState, useEffect } from 'react';
export function UserList() {
const [users, setUsers] = useState<User[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch('/api/users')
.then(res => res.json())
.then(data => {
setUsers(data);
setLoading(false);
});
}, []);
if (loading) return <p>Loading...</p>;
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
3. Custom Hook
import { useState, useCallback } from 'react';
function useToggle(initial = false): [boolean, () => void] {
const [value, setValue] = useState(initial);
const toggle = useCallback(() => setValue(v => !v), []);
return [value, toggle];
}
4. Context Pattern
import { createContext, useContext, useState, ReactNode } from 'react';
const ThemeContext = createContext<{ dark: boolean; toggle: () => void } | null>(null);
export function ThemeProvider({ children }: { children: ReactNode }) {
const [dark, setDark] = useState(false);
const toggle = () => setDark(d => !d);
return <ThemeContext.Provider value={{ dark, toggle }}>{children}</ThemeContext.Provider>;
}
export function useTheme() {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
return ctx;
}
Best Practices
- Keep components small and focused on a single responsibility
- Lift state up to the nearest common ancestor; use Context for deeply shared state
- Always provide a stable
keyprop when rendering lists - Clean up side effects in
useEffectreturn functions (subscriptions, timers) - Avoid creating new objects/functions inline in JSX to prevent unnecessary re-renders
- Use
React.lazyandSuspensefor code-splitting large routes
Resources
- Official documentation: https://react.dev/
- React hooks reference: https://react.dev/reference/react
- Create React App: https://create-react-app.dev/
Keywords
react, React Hooks, JSX, TSX, components, state, props, useEffect, useState, Context API, functional components, performance, memo, lazy loading
More from partme-ai/full-stack-skills
vite
Guidance for Vite using the official Guide, Config Reference, and Plugins pages. Use when the user needs Vite setup, configuration, or plugin selection details.
68element-plus-vue3
Provides comprehensive guidance for Element Plus Vue 3 component library including installation, components, themes, internationalization, and API reference. Use when the user asks about Element Plus for Vue 3, needs to build Vue 3 applications with Element Plus, or customize component styles.
63vue3
Guidance for Vue 3 using the official guide and API reference. Use when the user needs Vue 3 concepts, patterns, or API details to build components, apps, and tooling.
54electron
Build cross-platform desktop applications with Electron, covering main/renderer process architecture, IPC communication, BrowserWindow management, menus, tray icons, packaging, and security best practices. Use when the user asks about Electron, needs to create desktop applications, implement Electron features, or build cross-platform desktop apps.
51uniapp-project
Provides per-component and per-API examples with cross-platform compatibility details for uni-app, covering built-in components, uni-ui components, and APIs (network, storage, device, UI, navigation, media). Use when the user needs official uni-app components or APIs, wants per-component examples with doc links, or needs platform compatibility checks.
40ascii-cli-logo-banner
Entry point for ASCII CLI banners that routes to the Python built-in font skill or figlet.js/FIGfont skill. Use when the user wants a startup banner, ASCII logo, terminal welcome screen, or CLI branding for a service.
38