mirror of
https://github.com/kennethnym/aris.git
synced 2026-02-02 05:01:17 +00:00
- react-best-practices: Performance optimization patterns (client-side only) - web-design-guidelines: UI review against Web Interface Guidelines Co-authored-by: Ona <no-reply@ona.com>
728 B
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'} />
}