Back to Rendering Performance

Use Activity Component for Show/Hide

renderingactivityvisibilitystate-preservation
28.0k🕒 2026-06-10Source ↗

Install this skill

npx skills add vercel-labs/agent-skills

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

The Activity component provides a way to maintain the state and DOM node presence of components during visibility toggles. Unlike standard conditional rendering, which unmounts elements and triggers a full cleanup, Activity suspends the child component's interaction while keeping it alive in the background. This is particularly effective for heavy UI sections like data-rich dashboards, complex forms, or interactive charts that require significant computational cost to re-initialize. By using this, you prevent the recurring expenses associated with life-cycle triggers like useEffect or heavy memoized calculations every time a user shows or hides a sub-view. It optimizes perceived performance by keeping the internal React tree intact while signaling to the runtime that the specific branch is currently inactive, avoiding unnecessary layout recalculations and data refetching.

When to Use This Skill

  • Complex multi-tabbed interface management
  • Expanding and collapsing data-heavy accordion menus
  • Preserving form input values in a hidden modal
  • Maintaining map or canvas context during view switching

How to Invoke This Skill

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

  • Stop my component from unmounting when hidden
  • Keep state alive during toggle visibility
  • How to optimize expensive component re-renders
  • Preserve scroll position for dynamic UI tabs
  • Avoid react component cleanup on hide

What this skill does

  • Preserves component internal state across visibility cycles
  • Prevents unmounting of expensive DOM sub-trees
  • Reduces re-render overhead during frequent toggle interactions
  • Maintains scroll position for hidden UI elements
  • Avoids repetitive lifecycle method execution

When not to use it

  • Components with minimal rendering cost
  • Data-sensitive views that must clear state on close
  • Environments where memory usage is extremely constrained

Example workflow

  1. Identify a component that causes latency when toggled
  2. Wrap the target component in the Activity tag
  3. Assign the visibility state to the mode prop
  4. Verify component state persistence via browser console
  5. Audit memory footprint to ensure no leaks occur

Prerequisites

  • React 19 or experimental React channel
  • Components with substantial mounting overhead

Pitfalls & limitations

  • !Increased memory usage due to dormant component retention
  • !May trigger stale data if background updates are not managed
  • !Not suitable for components that rely on clean mounts for data fetching

FAQ

Does Activity clear component state?
No, that is the primary benefit. Activity preserves the state so the component remains exactly as it was before being hidden.
Is this different from CSS visibility: hidden?
Yes. While CSS visibility hides the element visually, Activity informs the React reconciler to treat the branch as inactive, which can optimize internal processing.
Can I use this for everything?
No, only use it for heavy components. Keeping every single component in memory with Activity will eventually degrade application performance.

How it compares

Unlike standard conditional rendering (which performs unmounts) or CSS-only toggling (which keeps nodes active but lacks lifecycle awareness), Activity gives React explicit intent to manage component state preservation.

Source & trust

28k stars🕒 Updated 2026-06-10
📄 Full skill instructions — original source: vercel-labs/agent-skills
## Use Activity Component for Show/Hide

Use React's <Activity> to preserve state/DOM for expensive components that frequently toggle visibility.

**Usage:**

import { Activity } from 'react'

function Dropdown({ isOpen }: Props) {
return (
<Activity mode={isOpen ? 'visible' : 'hidden'}>
<ExpensiveMenu />
</Activity>
)
}


Avoids expensive re-renders and state loss.

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-activity/
  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-activity/SKILL.md
  • Cursor: ~/.cursor/skills/vercel-labs/agent-skills/rendering-activity/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/vercel-labs/agent-skills/rendering-activity/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.