Back to Re-render Optimization

Extract to Memoized Components

rerendermemouseMemooptimization
28.0k🕒 2026-06-10Source ↗

Install this skill

npx skills add vercel-labs/agent-skills

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

This skill focuses on restructuring React components to prevent unnecessary execution of costly logic. By shifting heavy calculations or sub-component rendering into separate components wrapped in React.memo, developers can enforce early returns in parent components. When a parent conditional (such as a loading state) triggers, the child component code remains dormant rather than executing its expensive setup logic prematurely. This approach keeps main render functions clean and ensures that data processing only happens when the UI actually requires the rendered result. It serves as a tactical architectural pattern for isolating side effects and computational overhead from primary layout components. While automated tools like the React Compiler may eventually handle these optimizations, manual extraction remains a reliable technique for fine-grained control over component lifecycles in performance-sensitive interfaces.

When to Use This Skill

  • Handling heavy data processing or expensive utility calls before rendering a sub-view
  • Improving performance in layouts where specific conditional branches often return early
  • Decoupling complex UI widgets from their parent's primary state machine
  • Preventing UI freezes by avoiding unnecessary recalculations during loading states

How to Invoke This Skill

Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:

  • Extract this logic into a memoized component
  • Refactor this expensive calculation to a separate child component
  • Optimize this component to skip rendering when loading
  • Move this code into a memoized sub-component
  • Fix excessive re-renders by extracting the sub-component

What this skill does

  • Identifies expensive computation patterns inside parent components
  • Encapsulates sub-logic into isolated, memoized component structures
  • Enables conditional short-circuiting to prevent wasted render cycles
  • Reduces prop drilling by delegating data processing to child scopes
  • Optimizes memory usage by delaying component initialization

When not to use it

  • When using the React Compiler, which handles this optimization automatically
  • In simple components where the calculation cost is negligible or non-existent

Example workflow

  1. Identify a component containing expensive logic that should be skipped during loading states
  2. Create a new component file or block to house the isolated logic
  3. Wrap the new component definition with React.memo
  4. Move the heavy calculation from the parent scope into the new component
  5. Update the parent to conditionally render the new child component only when ready

Prerequisites

  • React
  • Basic understanding of component lifecycles
  • Knowledge of React.memo usage

Pitfalls & limitations

  • !Over-memoization can increase bundle size and introduce unnecessary complexity
  • !Risk of stale state if dependency arrays in nested hooks are incorrectly configured
  • !Maintenance overhead increases as logic is fragmented across multiple files

FAQ

Why not just use useMemo?
useMemo caches a value, but the parent component function must still run to reach that hook. Extracting to a component allows you to bail out of the entire sub-tree rendering process.
Is this still necessary with React Compiler?
No, if your project utilizes the React Compiler, it automatically manages memoization and component boundaries, making manual extraction for performance redundant.
Does this impact component props?
Yes, you must pass all necessary data as props to the new child component, which may lead to prop drilling if not managed carefully.

How it compares

Unlike manual useMemo caching which still executes the parent body, this method physically separates code to bypass execution entirely, offering superior performance control.

Source & trust

28k stars🕒 Updated 2026-06-10
📄 Full skill instructions — original source: vercel-labs/agent-skills
## Extract to Memoized Components

Extract expensive work into memoized components to enable early returns before computation.

**Incorrect (computes avatar even when loading):**

function Profile({ user, loading }: Props) {
const avatar = useMemo(() => {
const id = computeAvatarId(user)
return <Avatar id={id} />
}, [user])

if (loading) return <Skeleton />
return <div>{avatar}</div>
}


**Correct (skips computation when loading):**

const UserAvatar = memo(function UserAvatar({ user }: { user: User }) {
const id = useMemo(() => computeAvatarId(user), [user])
return <Avatar id={id} />
})

function Profile({ user, loading }: Props) {
if (loading) return <Skeleton />
return (
<div>
<UserAvatar user={user} />
</div>
)
}


**Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, manual memoization with memo() and useMemo() is not necessary. The compiler automatically optimizes re-renders.

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/rerender-memo/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/vercel-labs/agent-skills/rerender-memo/SKILL.md
  • Cursor: ~/.cursor/skills/vercel-labs/agent-skills/rerender-memo/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/vercel-labs/agent-skills/rerender-memo/SKILL.md

🚀 Install with CLI:
npx skills add vercel-labs/agent-skills

Read the Master Guide: Mastering Agent Skills

Recommended Rules

View more rules

Recommended Workflows

View more workflows

Recommended MCP Servers

View more MCP servers

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid re-render optimization issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Re-render Optimization and is published by Vercel Engineering, maintained in vercel-labs/agent-skills.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.