Back to Rendering Performance

Hoist Static JSX Elements

renderingjsxstaticoptimization
28.0k🕒 2026-06-10Source ↗

Install this skill

npx skills add vercel-labs/agent-skills

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

Hoisting static JSX elements involves moving constant UI fragments outside of the functional component scope. By defining static markup—such as complex SVG paths, layout placeholders, or static icons—as a standalone constant at the module level, you prevent these elements from being re-instantiated during every component render cycle. In standard React reconciliation, defining JSX inside a component body triggers new object creation each time the component updates. Lifting these definitions to the top level preserves referential identity, reducing the workload on the virtual DOM diffing process and lowering CPU overhead for frequent re-renders. This pattern is particularly effective for heavy static assets or shared structural wrappers that do not depend on component state or props, ultimately smoothing out frame drops and optimizing the performance profile of computationally expensive interfaces.

When to Use This Skill

  • Extracting large, static SVG illustrations or iconography
  • Defining persistent layout shells or structural placeholders
  • Managing static loading skeletons that require no dynamic props
  • Optimizing deep component trees with numerous static decorative elements
  • Refactoring codebases to reduce memory pressure in high-frequency update loops

How to Invoke This Skill

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

  • Hoist static JSX elements for performance
  • Move static components outside the render function
  • Fix object recreation for static JSX
  • Refactor static nodes to improve re-render speed
  • How do I prevent static JSX from re-rendering?

What this skill does

  • Identifies static JSX trees suitable for module-level extraction
  • Preserves referential integrity for non-dynamic UI components
  • Reduces object allocation frequency during component lifecycle updates
  • Optimizes memory footprint by sharing static instances across renders
  • Minimizes unnecessary virtual DOM re-evaluation for unchanging nodes

When not to use it

  • When the JSX relies on props or local component state
  • When using modern build setups with React Compiler enabled
  • When the element is small enough that the complexity of hoisting outweighs the performance gain

Example workflow

  1. Identify a large, unchanging JSX block inside a functional component
  2. Verify the block does not rely on local props or state
  3. Move the JSX declaration to the top-level module scope
  4. Replace the local JSX call with a reference to the new constant
  5. Run performance profiling to confirm reduction in re-renders

Pitfalls & limitations

  • !Accidentally referencing component-scoped variables in hoisted JSX
  • !Attempting to hoist elements that need to react to state changes
  • !Loss of readability if too many constants crowd the top of the file

FAQ

Why not just use useMemo?
While useMemo keeps a reference stable across renders, it still executes the function on every call. Hoisting the JSX outside the component ensures it is defined only once when the module loads.
Does React Compiler make this obsolete?
Yes, if your build pipeline includes the React Compiler, it automatically hoists static elements, making manual extraction redundant.
Can I hoist JSX that uses props?
No. Hoisted elements are defined outside the component and cannot access scope-specific data like props or state.
Is this approach always faster?
It is faster for large or complex elements, but for simple elements, the impact on performance is negligible and may negatively affect code maintainability.

How it compares

Manual hoisting ensures strict referential equality at the module level, whereas generic approaches might rely on unstable patterns like useMemo or standard render cycles that create redundant object garbage.

Source & trust

28k stars🕒 Updated 2026-06-10
📄 Full skill instructions — original source: vercel-labs/agent-skills
## Hoist Static JSX Elements

Extract static JSX outside components to avoid re-creation.

**Incorrect (recreates element every render):**

function LoadingSkeleton() {
return <div className="animate-pulse h-20 bg-gray-200" />
}

function Container() {
return (
<div>
{loading && <LoadingSkeleton />}
</div>
)
}


**Correct (reuses same element):**

const loadingSkeleton = (
<div className="animate-pulse h-20 bg-gray-200" />
)

function Container() {
return (
<div>
{loading && loadingSkeleton}
</div>
)
}


This is especially helpful for large and static SVG nodes, which can be expensive to recreate on every render.

**Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, the compiler automatically hoists static JSX elements and optimizes component re-renders, making manual hoisting unnecessary.

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/rendering-hoist-jsx/
  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/rendering-hoist-jsx/SKILL.md
  • Cursor: ~/.cursor/skills/vercel-labs/agent-skills/rendering-hoist-jsx/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/vercel-labs/agent-skills/rendering-hoist-jsx/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 rendering performance 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 Rendering Performance and is published by Vercel Engineering, maintained in vercel-labs/agent-skills.

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