Skills included: - pr-reviewer: Adapted for Gitea/GitHub via platform-aware scripts (dropped fetch_pr_data.py and add_inline_comment.py, kept generate_review_files.py) - code-review-excellence: Methodology and checklists (React, TS, Python, etc.) - vercel-react-best-practices: 57 rules for React/Next.js performance - tailwind-design-system: Tailwind CSS v4 patterns, CVA, design tokens New shell scripts added to ~/.claude/scripts/git/: - pr-diff.sh: Get PR diff (GitHub gh / Gitea API) - pr-metadata.sh: Get PR metadata as normalized JSON Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
1018 B
Markdown
36 lines
1018 B
Markdown
---
|
|
title: Do not wrap a simple expression with a primitive result type in useMemo
|
|
impact: LOW-MEDIUM
|
|
impactDescription: wasted computation on every render
|
|
tags: rerender, useMemo, optimization
|
|
---
|
|
|
|
## Do not wrap a simple expression with a primitive result type in useMemo
|
|
|
|
When an expression is simple (few logical or arithmetical operators) and has a primitive result type (boolean, number, string), do not wrap it in `useMemo`.
|
|
Calling `useMemo` and comparing hook dependencies may consume more resources than the expression itself.
|
|
|
|
**Incorrect:**
|
|
|
|
```tsx
|
|
function Header({ user, notifications }: Props) {
|
|
const isLoading = useMemo(() => {
|
|
return user.isLoading || notifications.isLoading
|
|
}, [user.isLoading, notifications.isLoading])
|
|
|
|
if (isLoading) return <Skeleton />
|
|
// return some markup
|
|
}
|
|
```
|
|
|
|
**Correct:**
|
|
|
|
```tsx
|
|
function Header({ user, notifications }: Props) {
|
|
const isLoading = user.isLoading || notifications.isLoading
|
|
|
|
if (isLoading) return <Skeleton />
|
|
// return some markup
|
|
}
|
|
```
|