Skip to main content
rule CX Codex

rerender-memo-with-default-value — Claude Code rule

rerender-memo-with-default-value — a rule that prevents memoization from breaking when React components have default values (functions, objects, arrays) in parameters. It instructs you to extract these defaults into module-level constants.

MIT ★ 7,191 updated 2026-10-24

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

What rerender-memo-with-default-value does

When a memoized React component declares an optional parameter with a default non-primitive value—such as a function, object, or array—calling the component without that parameter creates a new instance on each render. Since memo() relies on strict equality comparison, these fresh instances fail the check, and memoization breaks.

The rule shows how to move the default value outside the component into a constant. Instead of { onClick = () => {} } inline, define const NOOP = () => {} at module scope and use { onClick = NOOP } in the parameter list. This keeps the value stable across renders.

Once installed in .claude/rules/rerender-memo-with-default-value.md, Claude Code applies the rule automatically when reviewing React code.

What it helps with

  • Fix broken memoization in components with default function parameters
  • Stop unnecessary rerenders caused by new object instances
  • Extract unstable defaults into constants to restore memo efficiency

Example prompts for the agent

  • Review my UserAvatar component where onClick defaults to () => {} and suggest a fix
  • Find all memoized components in this file that have object or function defaults
  • Refactor optional parameters in memo() components so memoization actually works

How to install rerender-memo-with-default-value

Manually: put the files in place

.claude/rules/rerender-memo-with-default-value.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-memo-with-default-value

How do I install the rerender-memo-with-default-value rule in Claude Code?

Place the rule file at .claude/rules/rerender-memo-with-default-value.md. Claude Code automatically loads all rules from that directory when you open your project.

What does this rule do?

The rule detects when a memoized React component has a default value for a parameter (a function, object, or array) defined inline in the function signature. This breaks memoization because a new instance is created on every render. The rule recommends extracting that default into a constant.

Why does memo() not work when defaults are functions in the parameter list?

The memo() function compares props using strict equality (===). If a default is defined as () => {}, a fresh function is created on each render. Since they are different instances, memo() sees the props as changed and rerenders the component.

Source text

rerender-memo-with-default-value.md · MIT
---

title: Extract Default Non-primitive Parameter Value from Memoized Component to Constant
impact: MEDIUM
impactDescription: restores memoization by using a constant for default value
tags: rerender, memo, optimization

---

## Extract Default Non-primitive Parameter Value from Memoized Component to Constant

When memoized component has a default value for some non-primitive optional parameter, such as an array, function, or object, calling the component without that parameter results in broken memoization. This is because new value instances are created on every rerender, and they do not pass strict equality comparison in `memo()`.

To address this issue, extract the default value into a constant.

**Incorrect (`onClick` has different values on every rerender):**

```tsx
const UserAvatar = memo(function UserAvatar({ onClick = () => {} }: { onClick?: () => void }) {
  // ...
})

// Used without optional onClick
<UserAvatar />
```

**Correct (stable default value):**

```tsx
const NOOP = () => {};

const UserAvatar = memo(function UserAvatar({ onClick = NOOP }: { onClick?: () => void }) {
  // ...
})

// Used without optional onClick
<UserAvatar />
```

© 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 →
js-early-exit The js-early-exit rule recommends returning as soon as a function’s result is clear. It fits checks where continuing after the first error serves no purpose. CX Codex +1 ★ 7,191repo stars rerender-memo rerender-memo — a rule that guides your agent to extract expensive computations into memoized components, enabling early returns without triggering child logic. Speeds up React re-render paths. CX Codex +1 ★ 7,191repo stars bundle-preload bundle-preload directs the agent to preload heavy JavaScript chunks on user intent like hover or focus. This cuts perceived interface latency. CX Codex +1 ★ 7,191repo stars client-swr-dedup The client-swr-dedup rule recommends SWR to share requests between component instances and reuse cached data. It fits React projects that fetch data on the client. CX Codex +1 ★ 7,191repo stars rendering-animate-svg-wrapper rendering-animate-svg-wrapper enforces wrapping svg elements in an outer div container for CSS animations. Enables GPU hardware acceleration across browsers. CX Codex +1 ★ 7,191repo stars rerender-derived-state-no-effect The rerender-derived-state-no-effect rule keeps derived values out of React state and avoids effects that mirror props. Use it when reviewing components for extra renders and state drift. CX Codex +1 ★ 7,191repo stars rerender-move-effect-to-event rerender-move-effect-to-event tells the agent to fire a side effect from the handler that caused it, not from useEffect watching a state flag. CX Codex +1 ★ 7,191repo stars async-dependencies async-dependencies instructs Claude Code to execute partially dependent async tasks concurrently using better-all or native promise chains rather than blocking Promise.all calls. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open