Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/rerender-simple-expression-in-memo.md
Open on GitHub

What 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 useMemo around 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 useMemo from 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 useMemo unnecessarily.

How to install rerender-simple-expression-in-memo

Manually: put the files in place

.claude/rules/rerender-simple-expression-in-memo.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set130

The whole set →
advanced-init-once advanced-init-once prevents running app-wide startup logic inside component useEffect([]) hooks and suggests module-level guards or top-level initialization instead. CX Codex +1 ★ 7,191repo stars rerender-defer-reads The rerender-defer-reads rule keeps callback-only reads of dynamic state out of component subscriptions. Use it when searchParams or localStorage is needed only after an action. CX Codex +1 ★ 7,191repo stars rendering-conditional-render The rendering-conditional-render rule prevents accidental rendering of zeros and NaN in JSX. It enforces explicit ternary operators instead of && checks, so falsy values stay out of the DOM. CX Codex +1 ★ 7,191repo stars server-serialization server-serialization is a Claude Code rule for limiting data passed across React Server/Client boundaries. It applies when client components receive props from server components. CX Codex +1 ★ 7,191repo stars js-hoist-regexp js-hoist-regexp — a Claude rule that keeps RegExp construction out of the render path: define the pattern at module scope or wrap it in useMemo(). CX Codex +1 ★ 7,191repo stars rendering-hoist-jsx rendering-hoist-jsx extracts static JSX elements outside components to prevent element re-creation on every render pass. CX Codex +1 ★ 7,191repo stars rerender-transitions The rerender-transitions rule marks frequent, non-urgent state changes as transitions. It fits React code where updates such as scroll tracking should keep the interface responsive. CX Codex +1 ★ 7,191repo stars advanced-use-latest advanced-use-latest — a Claude rule file on reaching fresh callback values inside a React effect and keeping the dependency array down to state. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open