Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/rerender-dependencies.md
1---2title: Narrow Effect Dependencies3impact: LOW4impactDescription: minimizes effect re-runs5tags: rerender, useEffect, dependencies, optimization6---78## Narrow Effect Dependencies910Specify primitive dependencies instead of objects to minimize effect re-runs.1112**Incorrect (re-runs on any user field change):**1314```tsx15useEffect(() => {16console.log(user.id)17}, [user])18```1920**Correct (re-runs only when id changes):**2122```tsx23useEffect(() => {24console.log(user.id)25}, [user.id])26```2728**For derived state, compute outside effect:**2930```tsx31// Incorrect: runs on width=767, 766, 765...32useEffect(() => {33if (width < 768) {34enableMobileMode()35}36}, [width])3738// Correct: runs only on boolean transition39const isMobile = width < 76840useEffect(() => {41if (isMobile) {42enableMobileMode()43}44}, [isMobile])45```46