Files
aiworker/.gemini/skills/vercel-react-best-practices/rules/rerender-derived-state.md
Hector Ros dcaaef1011 Unify past-sessions naming format
Format: YYYY-MM-DD-description.md
- 2026-01-19-infrastructure-deployment.md
- 2026-01-19-backend-api-implementation.md (in progress)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-01-20 01:07:17 +01:00

728 B

title, impact, impactDescription, tags
title impact impactDescription tags
Subscribe to Derived State MEDIUM reduces re-render frequency rerender, derived-state, media-query, optimization

Subscribe to Derived State

Subscribe to derived boolean state instead of continuous values to reduce re-render frequency.

Incorrect (re-renders on every pixel change):

function Sidebar() {
  const width = useWindowWidth()  // updates continuously
  const isMobile = width < 768
  return <nav className={isMobile ? 'mobile' : 'desktop'} />
}

Correct (re-renders only when boolean changes):

function Sidebar() {
  const isMobile = useMediaQuery('(max-width: 767px)')
  return <nav className={isMobile ? 'mobile' : 'desktop'} />
}