epic-react-patterns
Guide on React patterns, performance optimization, and code quality for Epic Stack
Install
mkdir -p .claude/skills/epic-react-patterns && curl -L -o skill.zip "https://mcp.directory/api/skills/download/4515" && unzip -o skill.zip -d .claude/skills/epic-react-patterns && rm skill.zipInstalls to .claude/skills/epic-react-patterns
About this skill
Epic Stack: React Patterns and Guidelines
When to use this skill
Use this skill when you need to:
- Write efficient React components in Epic Stack applications
- Optimize performance and bundle size
- Follow React Router patterns and conventions
- Avoid common React anti-patterns
- Implement proper code splitting
- Optimize re-renders and data fetching
- Use React hooks correctly
Philosophy
Following Epic Web principles:
- Make it work, make it right, make it fast - In that order. First make it functional, then refactor for clarity, then optimize for performance.
- Pragmatism over purity - Choose practical solutions that work well in your context rather than theoretically perfect ones.
- Optimize for sustainable velocity - Write code that's easy to maintain and extend, not just fast to write initially.
- Do as little as possible - Only add complexity when it provides real value.
Patterns and conventions
Data Fetching in React Router
Epic Stack uses React Router loaders for data fetching, not useEffect.
✅ Good - Use loaders:
// app/routes/users/$username.tsx
export async function loader({ params }: Route.LoaderArgs) {
const user = await prisma.user.findUnique({
where: { username: params.username },
})
return { user }
}
export default function UserRoute({ loaderData }: Route.ComponentProps) {
return <div>{loaderData.user.name}</div>
}
❌ Avoid - Don't fetch in useEffect:
// ❌ Don't do this
export default function UserRoute({ params }: Route.ComponentProps) {
const [user, setUser] = useState(null)
useEffect(() => {
fetch(`/api/users/${params.username}`)
.then(res => res.json())
.then(setUser)
}, [params.username])
return user ? <div>{user.name}</div> : <div>Loading...</div>
}
Avoid useEffect for Side Effects
Instead of using useEffect, use event handlers, CSS, ref callbacks, or
useSyncExternalStore.
✅ Good - Use event handlers:
function ProductPage({ product, addToCart }: Route.ComponentProps) {
function buyProduct() {
addToCart(product)
showNotification(`Added ${product.name} to cart!`)
}
function handleBuyClick() {
buyProduct()
}
function handleCheckoutClick() {
buyProduct()
navigate('/checkout')
}
return (
<div>
<button onClick={handleBuyClick}>Buy Now</button>
<button onClick={handleCheckoutClick}>Checkout</button>
</div>
)
}
❌ Avoid - Side effects in useEffect:
// ❌ Don't do this
function ProductPage({ product, addToCart }: Route.ComponentProps) {
useEffect(() => {
if (product.isInCart) {
showNotification(`Added ${product.name} to cart!`)
}
}, [product])
function handleBuyClick() {
addToCart(product)
}
// ...
}
✅ Appropriate use of useEffect:
// ✅ Good - Event listeners are appropriate
useEffect(() => {
const controller = new AbortController()
window.addEventListener(
'keydown',
(event: KeyboardEvent) => {
if (event.key !== 'Escape') return
// handle escape key
},
{ signal: controller.signal },
)
return () => {
controller.abort()
}
}, [])
Code Splitting with React Router
React Router automatically code-splits by route. Use dynamic imports for heavy components.
✅ Good - Dynamic imports:
// app/routes/admin/dashboard.tsx
import { lazy } from 'react'
const AdminChart = lazy(() => import('#app/components/admin/chart.tsx'))
export default function AdminDashboard() {
return (
<Suspense fallback={<div>Loading chart...</div>}>
<AdminChart />
</Suspense>
)
}
Optimizing Re-renders
✅ Good - Memoize expensive computations:
import { useMemo } from 'react'
function UserList({ users }: { users: User[] }) {
const sortedUsers = useMemo(() => {
return [...users].sort((a, b) => a.name.localeCompare(b.name))
}, [users])
return (
<ul>
{sortedUsers.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
)
}
✅ Good - Memoize callbacks:
import { useCallback } from 'react'
function NoteEditor({ noteId, onSave }: { noteId: string; onSave: (note: Note) => void }) {
const handleSave = useCallback((note: Note) => {
onSave(note)
}, [onSave])
return <Editor onSave={handleSave} />
}
❌ Avoid - Unnecessary memoization:
// ❌ Don't memoize simple values
const count = useMemo(() => items.length, [items]) // Just use items.length directly
// ❌ Don't memoize simple callbacks
const handleClick = useCallback(() => {
console.log('clicked')
}, []) // Just define the function normally if it doesn't need memoization
Bundle Size Optimization
✅ Good - Import only what you need:
// ✅ Import specific functions
import { useSearchParams } from 'react-router'
import { parseWithZod } from '@conform-to/zod'
❌ Avoid - Barrel imports:
// ❌ Don't import entire libraries if you only need one thing
import * as ReactRouter from 'react-router'
import * as Conform from '@conform-to/zod'
Form Handling with Conform
✅ Good - Use Conform for forms:
import { useForm, getFormProps } from '@conform-to/react'
import { parseWithZod } from '@conform-to/zod'
import { Form } from 'react-router'
const SignupSchema = z.object({
email: z.string().email(),
password: z.string().min(6),
})
export default function SignupRoute({ actionData }: Route.ComponentProps) {
const [form, fields] = useForm({
id: 'signup-form',
lastResult: actionData?.result,
onValidate({ formData }) {
return parseWithZod(formData, { schema: SignupSchema })
},
})
return (
<Form method="POST" {...getFormProps(form)}>
{/* form fields */}
</Form>
)
}
Component Composition
✅ Good - Compose components:
function UserProfile({ user }: { user: User }) {
return (
<Card>
<UserHeader user={user} />
<UserDetails user={user} />
<UserActions userId={user.id} />
</Card>
)
}
❌ Avoid - Large monolithic components:
// ❌ Don't put everything in one component
function UserProfile({ user }: { user: User }) {
return (
<div className="card">
<div className="header">
<img src={user.avatar} alt={user.name} />
<h1>{user.name}</h1>
</div>
<div className="details">
<p>{user.email}</p>
<p>{user.bio}</p>
</div>
<div className="actions">
<button>Edit</button>
<button>Delete</button>
</div>
</div>
)
}
Error Boundaries
✅ Good - Use error boundaries:
// app/routes/users/$username.tsx
export function ErrorBoundary() {
return (
<GeneralErrorBoundary
statusHandlers={{
404: ({ params }) => (
<p>User "{params.username}" not found</p>
),
}}
/>
)
}
TypeScript Guidelines
✅ Good - Type props explicitly:
interface UserCardProps {
user: {
id: string
name: string
email: string
}
onEdit?: (userId: string) => void
}
function UserCard({ user, onEdit }: UserCardProps) {
return (
<div>
<h2>{user.name}</h2>
<p>{user.email}</p>
{onEdit && <button onClick={() => onEdit(user.id)}>Edit</button>}
</div>
)
}
✅ Good - Use Route types:
import type { Route } from './+types/users.$username'
export async function loader({ params }: Route.LoaderArgs) {
// params is type-safe!
const user = await prisma.user.findUnique({
where: { username: params.username },
})
return { user }
}
export default function UserRoute({ loaderData }: Route.ComponentProps) {
// loaderData is type-safe!
return <div>{loaderData.user.name}</div>
}
Loading States
✅ Good - Use React Router's pending states:
import { useNavigation } from 'react-router'
function NoteForm() {
const navigation = useNavigation()
const isSubmitting = navigation.state === 'submitting'
return (
<Form method="POST">
<button type="submit" disabled={isSubmitting}>
{isSubmitting ? 'Saving...' : 'Save'}
</button>
</Form>
)
}
Preventing Data Fetching Waterfalls
React Router loaders can prevent waterfalls by fetching data in parallel.
❌ Avoid - Sequential data fetching (waterfall):
// ❌ Don't do this - creates a waterfall
export async function loader({ params }: Route.LoaderArgs) {
const user = await prisma.user.findUnique({
where: { username: params.username },
})
// Second fetch waits for first to complete
const notes = await prisma.note.findMany({
where: { ownerId: user.id },
})
return { user, notes }
}
✅ Good - Parallel data fetching:
// ✅ Fetch data in parallel
export async function loader({ params }: Route.LoaderArgs) {
const user = await prisma.user.findUnique({
where: { username: params.username },
select: { id: true, username: true, name: true },
})
// Fetch notes in parallel with user data
const [notes, stats] = await Promise.all([
user
? prisma.note.findMany({
where: { ownerId: user.id },
select: { id: true, title: true, updatedAt: true },
})
: Promise.resolve([]),
user
? prisma.note.count({ where: { ownerId: user.id } })
: Promise.resolve(0),
])
return { user, notes, stats }
}
✅ Good - Nested route parallel loading:
// Parent route loader
// app/routes/users/$username.tsx
export async function loader({ params }: Route.LoaderArgs) {
const user = await prisma.user.findUnique({
where: { username: params.username },
select: { id: true, username: true, name: true },
})
return { user }
}
// Child route loader runs in parallel
// app/routes/users/$username/notes.tsx
export async function loader({ params }: Route.LoaderArgs) {
const user = await prisma.user.findUnique({
where: { username: params.username },
select: { id: true },
})
if (!user) {
throw new Response('Not Found', { status:
---
*Content truncated.*
More by epicweb-dev
View all skills by epicweb-dev →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
pdf-to-markdown
aliceisjustplaying
Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.
Related MCP Servers
Browse all serversGet expert React Native software guidance with tools for component analysis, performance, debugging, and migration betwe
Boost Postgres performance with Postgres MCP Pro—AI-driven index tuning, health checks, and safe, intelligent SQL optimi
DeepWiki converts deepwiki.com pages into clean Markdown, with fast, secure extraction—perfect as a PDF text, page, or i
Optimize Facebook ad campaigns with AI-driven insights, creative analysis, and campaign control in Meta Ads Manager for
Explore Magic UI, a React UI library offering structured component access, code suggestions, and installation guides for
Ripgrep offers high-performance text search, ideal for SEO optimization software and rapid content discovery across loca
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.