React Skill
Loaded by: Frontend Division agents | Version: 1.0
Best Practices
Component Structure
- •Use functional components with hooks (no class components)
- •Keep components under 200 lines; one component per file
- •Co-locate related files (component, styles, tests, types)
Hooks
- •Custom hooks for reusable logic (prefix with
use) - •
useStatefor simple local state;useReducerfor complex state - •
useEffectcleanup to prevent memory leaks - •
useMemo/useCallbackonly when measurably needed
Performance
- •React.lazy for route-level code splitting
- •React.memo for expensive pure components
- •Avoid inline object/array creation in JSX props
- •Use stable keys in lists (never array index)
Pattern
tsx
interface UserCardProps {
name: string;
email: string;
onEdit?: () => void;
}
const UserCard: React.FC<UserCardProps> = ({ name, email, onEdit }) => (
<div className="user-card">
<h3>{name}</h3>
<p>{email}</p>
{onEdit && <button onClick={onEdit}>Edit</button>}
</div>
);
export default UserCard;
Anti-Patterns
- •Do NOT use
anytype - •Do NOT mutate state directly
- •Do NOT put business logic in components
- •Do NOT use
useEffectfor derived state - •Do NOT create components inside render
Checklist
- • Component is typed with TypeScript interfaces
- • Props have sensible defaults
- • No
anytypes - • Effects have cleanup functions where needed
- • Component is under 200 lines
- • Error boundaries wrap risky components