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-derived-state.md
1---2title: Subscribe to Derived State3impact: MEDIUM4impactDescription: reduces re-render frequency5tags: rerender, derived-state, media-query, optimization6---78## Subscribe to Derived State910Subscribe to derived boolean state instead of continuous values to reduce re-render frequency.1112**Incorrect (re-renders on every pixel change):**1314```tsx15function Sidebar() {16const width = useWindowWidth() // updates continuously17const isMobile = width < 76818return <nav className={isMobile ? 'mobile' : 'desktop'} />19}20```2122**Correct (re-renders only when boolean changes):**2324```tsx25function Sidebar() {26const isMobile = useMediaQuery('(max-width: 767px)')27return <nav className={isMobile ? 'mobile' : 'desktop'} />28}29```30