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-simple-expression-in-memo.md
1---2title: Do not wrap a simple expression with a primitive result type in useMemo3impact: LOW-MEDIUM4impactDescription: wasted computation on every render5tags: rerender, useMemo, optimization6---78## Do not wrap a simple expression with a primitive result type in useMemo910When an expression is simple (few logical or arithmetical operators) and has a primitive result type (boolean, number, string), do not wrap it in `useMemo`.11Calling `useMemo` and comparing hook dependencies may consume more resources than the expression itself.1213**Incorrect:**1415```tsx16function Header({ user, notifications }: Props) {17const isLoading = useMemo(() => {18return user.isLoading || notifications.isLoading19}, [user.isLoading, notifications.isLoading])2021if (isLoading) return <Skeleton />22// return some markup23}24```2526**Correct:**2728```tsx29function Header({ user, notifications }: Props) {30const isLoading = user.isLoading || notifications.isLoading3132if (isLoading) return <Skeleton />33// return some markup34}35```36