rerender-simple-expression-in-memo — Claude Code rule
The rerender-simple-expression-in-memo rule advises against using useMemo for simple expressions that return a boolean, number, or string. It applies when reviewing React component calculations.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/rerender-simple-expression-in-memo.mdWhat rerender-simple-expression-in-memo does
The rule targets simple logical or arithmetic expressions with primitive results: boolean, number, or string. For instance, a loading flag derived from two boolean properties can be assigned directly instead of being wrapped in useMemo.
Calling useMemo and checking its dependencies can cost more than evaluating the expression. The rule therefore favors a plain assignment for this case. Add .claude/rules/rerender-simple-expression-in-memo.md to use it in Claude Code; expressions with non-primitive results fall outside the stated guidance.
What it helps with
- remove
useMemoaround a simple boolean expression - calculate a number without adding a hook
- decide whether a simple string needs memoization
Example prompts for the agent
- Review this component and remove
useMemofrom simple expressions with primitive results. - Check whether the loading flag can be derived directly from component properties.
- Find simple calculations in this component that use
useMemounnecessarily.
How to install rerender-simple-expression-in-memo
Manually: put the files in place
.claude/rules/rerender-simple-expression-in-memo.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/rerender-simple-expression-in-memo.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/rerender-simple-expression-in-memo.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/rerender-simple-expression-in-memo.mdManually: put the files in place
.clinerules/rerender-simple-expression-in-memo.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about rerender-simple-expression-in-memo
How do I install rerender-simple-expression-in-memo in Claude Code?
Add the rule at .claude/rules/rerender-simple-expression-in-memo.md.
What does rerender-simple-expression-in-memo do?
It recommends leaving simple logical or arithmetic expressions out of useMemo when they return a boolean, number, or string.
Which expressions does the rule cover?
It covers simple expressions with primitive results: boolean, number, or string. Simplicity is described in terms of the number of logical or arithmetic operators.
Source text
rerender-simple-expression-in-memo.md · MIT
---
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
}
```
© tech-leads-club · MIT · tech-leads-club/agent-skills