Back to Re-render Optimization

Narrow Effect Dependencies

rerenderuseEffectdependenciesoptimization
28.0k🕒 2026-06-10Source ↗

Install this skill

npx skills add vercel-labs/agent-skills

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

Narrow Effect Dependencies is a React optimization technique focused on refining the trigger conditions for useEffect hooks. By default, developers often pass whole objects or arrays into dependency lists, causing side effects to execute whenever any internal property of that object updates. This skill enforces the practice of passing specific primitive values instead of complex structures, preventing unnecessary re-execution of logic. It also encourages pulling derived state calculations out of the effect body and into the component scope. By isolating exact dependencies, you minimize computational overhead, avoid stale closures, and prevent infinite loops in your component tree. This approach leads to more predictable rendering cycles and helps maintain clean, performant React applications by ensuring effects only react to meaningful data changes.

When to Use This Skill

  • Optimizing effects triggered by large user profile objects
  • Handling mobile/desktop viewport breakpoints efficiently
  • Preventing excessive API calls when only one field in a settings object changes
  • Syncing complex local state with external storage or DOM events

How to Invoke This Skill

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

  • optimize my useEffect dependency list
  • why does my effect run too many times
  • reduce re-renders in my react component
  • narrow down my react effect triggers
  • convert object dependency to primitive dependency

What this skill does

  • Reduces re-render overhead by isolating specific data points
  • Converts complex object dependencies into primitive dependencies
  • Extracts logic into derived variables to prevent effect churn
  • Identifies unnecessary effect cycles caused by broad array dependencies
  • Optimizes state management by narrowing effect trigger scope

When not to use it

  • When an object is deeply nested and requires monitoring of multiple unpredictable keys
  • If the code readability significantly degrades by destructuring a massive state object

Example workflow

  1. Identify a useEffect hook that triggers more frequently than expected.
  2. Inspect the current dependency array for object or array references.
  3. Extract the necessary primitive fields from the object.
  4. Move conditional logic into a constant to create a boolean derived state.
  5. Update the dependency array to include only the new derived boolean.
  6. Verify the effect execution count via console logs or React DevTools.

Prerequisites

  • Understanding of the React useEffect hook lifecycle
  • Basic knowledge of referential equality in JavaScript

Pitfalls & limitations

  • !Accidentally creating new object references in the component body that trigger the effect anyway
  • !Missing essential dependencies when overly aggressive in narrowing
  • !Complexity creep when extracting too many derived values

FAQ

Why is passing an entire object into a dependency list bad?
React uses referential equality to check dependencies. If any property of the object changes, the reference might trigger the effect, even if the specific value you care about stayed the same.
How does derived state help with performance?
Calculating state outside the effect ensures the logic runs during the render phase. This keeps the effect focused purely on side-effect execution rather than status checking.
Can I use this for deep object comparisons?
This technique is meant for narrowing to primitives. For deep object comparison, consider memoization or custom equality checks rather than relying on the dependency array.

How it compares

While manual optimization requires manually auditing every dependency, this skill provides a structural pattern that programmatically enforces tighter execution cycles.

Source & trust

28k stars🕒 Updated 2026-06-10
📄 Full skill instructions — original source: vercel-labs/agent-skills
## Narrow Effect Dependencies

Specify primitive dependencies instead of objects to minimize effect re-runs.

**Incorrect (re-runs on any user field change):**

useEffect(() => {
console.log(user.id)
}, [user])


**Correct (re-runs only when id changes):**

useEffect(() => {
console.log(user.id)
}, [user.id])


**For derived state, compute outside effect:**

// Incorrect: runs on width=767, 766, 765...
useEffect(() => {
if (width < 768) {
enableMobileMode()
}
}, [width])

// Correct: runs only on boolean transition
const isMobile = width < 768
useEffect(() => {
if (isMobile) {
enableMobileMode()
}
}, [isMobile])

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