/dev-infrastructure-skills:react-best-practicesfrom dev-infrastructure-skills
This skill should be used when the user asks to "write a React component", "optimize React performance", "fix React re-renders", "reduce bundle size", "eliminate waterfalls", "improve React patterns", "review React code", or needs guidance on React hooks, server components, data fetching, rendering optimization, or component architecture best practices.
Ships in dev-infrastructure-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Comprehensive React performance and architecture patterns organized by priority. Apply these rules when writing, reviewing, or optimizing React code.
Rules are organized into 8 categories by impact. Categories marked CRITICAL should always be checked.
Start async operations immediately but defer await until data is actually needed. This converts sequential fetches into parallel ones.
// BAD: Sequential — second fetch waits for first
async function Page() {
const user = await getUser();
const posts = await getPosts(user.id);
return <Feed user={user} posts={posts} />;
}
// GOOD: Parallel — both start immediately
async function Page() {
const userPromise = getUser();
const postsPromise = getPosts();
const user = await userPromise;
const posts = await postsPromise;
return <Feed user={user} posts={posts} />;
}
When fetches have dependencies, parallelize independent branches while respecting the dependency chain.
// GOOD: Parallel branches with dependencies
async function Dashboard() {
const [user, config] = await Promise.all([getUser(), getConfig()]);
const [posts, settings] = await Promise.all([
getPosts(user.id),
getUserSettings(user.id),
]);
return <DashboardView user={user} posts={posts} settings={settings} config={config} />;
}
Place <Suspense> boundaries to unlock parallel streaming. Each boundary creates an independent loading unit.
// GOOD: Independent loading for each section
function Page() {
return (
<div>
<Suspense fallback={<HeaderSkeleton />}>
<Header />
</Suspense>
<Suspense fallback={<FeedSkeleton />}>
<Feed />
</Suspense>
<Suspense fallback={<SidebarSkeleton />}>
<Sidebar />
</Suspense>
</div>
);
}
Import directly from source modules, not barrel files (index.ts). Barrel imports pull in entire libraries.
// BAD: Imports entire library
import { Button } from '@/components';
// GOOD: Direct import
import { Button } from '@/components/ui/button';
For third-party libraries, use optimizePackageImports in next.config:
experimental: {
optimizePackageImports: ['lucide-react', '@heroicons/react', 'date-fns']
}
Load heavy modules only when the runtime context requires them:
// GOOD: Load only needed parser
async function parseDocument(type: string) {
if (type === 'pdf') {
const { parsePDF } = await import('./parsers/pdf');
return parsePDF;
}
const { parseText } = await import('./parsers/text');
return parseText;
}
Use next/dynamic or lazy loading for below-the-fold or interaction-triggered components:
const HeavyChart = dynamic(() => import('./HeavyChart'), {
loading: () => <ChartSkeleton />,
ssr: false,
});
Keep state as close to where it's used as possible. When parent state changes, all children re-render.
useMemo and useCallback StrategicallyOnly memoize when: (a) expensive computation, (b) referential equality matters for child components, or (c) dependency of other hooks.
// GOOD: Expensive filter operation
const filtered = useMemo(
() => items.filter(complexPredicate).sort(expensiveSort),
[items]
);
// BAD: Simple value — memoization overhead exceeds benefit
const label = useMemo(() => `Hello ${name}`, [name]);
When context values change often, split into multiple contexts or use composition:
// GOOD: Children passed as props don't re-render on parent state change
function Layout({ children }: { children: React.ReactNode }) {
const [count, setCount] = useState(0);
return (
<div>
<Counter count={count} setCount={setCount} />
{children} {/* Does NOT re-render when count changes */}
</div>
);
}
Components are Server Components by default. Only add 'use client' when you need:
useState, useEffect, or other hookswindow, document)onClick, onChange)// GOOD: Server component — no client JS, no loading state needed
async function UserProfile({ id }: { id: string }) {
const user = await db.users.findUnique({ where: { id } });
return <ProfileCard user={user} />;
}
Server-to-client props must be JSON-serializable:
Date → use .toISOString()Map/Set → convert to Object.fromEntries() / Array.from()When writing or reviewing React code, verify:
'use client' only when neededuseMemo/useCallback used only for genuinely expensive operationsFor the complete 40+ rule reference with all code examples, see references/.
Before emitting components, climb the ladder, native and stdlib first, no unrequested abstractions. See the ponytail skill — the YAGNI ladder (does it need to exist; stdlib before custom; native before dependency; one line before fifty), never cutting validation, error handling, security, or accessibility.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
5 skills in this plugin
/next-best-practicesThis skill should be used when the user asks to "create a Next.js page", "set up App Router", "use server components", "implement server actions", "configure Next.js caching", "add middleware", "optimize Next.js performance", "fix Next.js routing", or needs guidance on Next.js file conventions, RSC boundaries, data fetching patterns, async patterns (Next.js 15+), or 'use client'/'use server'/'use cache' directives.
/playwright-testingThis skill should be used when the user asks to "write E2E tests", "set up Playwright", "write browser tests", "test user flows", "automate browser testing", "fix flaky tests", "debug E2E failures", "add end-to-end testing", or needs guidance on Playwright locators, fixtures, page objects, accessibility testing, visual regression, mobile testing, or CI/CD test infrastructure.
/supabase-postgresThis skill should be used when the user asks to "write a Supabase query", "set up RLS policies", "create a migration", "optimize Postgres queries", "design a database schema", "use edge functions", "configure realtime", "fix database performance", or needs guidance on Supabase patterns, Row Level Security, connection management, indexing strategies, or Postgres best practices for SaaS applications.
/test-driven-developmentThis skill should be used when the user asks to "write tests first", "do TDD", "test-driven development", "write unit tests", "add test coverage", "create a test suite", "follow red-green-refactor", or needs guidance on testing workflows, test structure, mocking strategies, assertion patterns, or building confidence in code through automated testing.
npx claudepluginhub moxywolfllc/moxywolf-plugins --plugin dev-infrastructure-skills