rerender-memo — Claude Code rule: optimize React rendering
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.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/rerender-memo.mdWhat rerender-memo does
The rule shows why computing values inside useMemo can be wasteful: if the parent returns early (showing a skeleton or error state), those computations still ran. The fix is to move computation and rendering into a separate component wrapped with memo(). When the parent returns before rendering the child, no computation happens at all.
Examples use TypeScript and JSX, contrasting an incorrect pattern with useMemo inside the function against a correct one using memo() for the child component. One key note: if React Compiler is enabled in your project, manual memoization with memo() and useMemo() is unnecessary—the compiler handles optimization automatically.
What it helps with
- skip expensive computations when a parent returns early
- structure components correctly for memoization
- know when
useMemoalone is not enough andmemo()is needed
Example prompts for the agent
- Show me how to move the avatar into its own component so it does not recalculate during loading
- Give an example where wrapping with
memo()prevents an expensive child from running - Refactor this so complex work does not start until data arrives
How to install rerender-memo
Manually: put the files in place
.claude/rules/rerender-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-memo.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/rerender-memo.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/rerender-memo.mdManually: put the files in place
.clinerules/rerender-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-memo
How do I install rerender-memo in Claude Code?
Place the rule file at .claude/rules/rerender-memo.md in your project root. Claude Code will apply it when analyzing and generating code.
What does the rerender-memo rule do?
It teaches your agent to move expensive computations into memoized components so they do not run when the parent exits early—such as during loading or on error.
Do I need this rule if my project has React Compiler?
No. React Compiler automatically optimizes re-renders, so manual memoization with memo() and useMemo() is not necessary.
Source text
rerender-memo.md · MIT
---
title: Extract to Memoized Components
impact: MEDIUM
impactDescription: enables early returns
tags: rerender, memo, useMemo, optimization
---
## Extract to Memoized Components
Extract expensive work into memoized components to enable early returns before computation.
**Incorrect (computes avatar even when loading):**
```tsx
function Profile({ user, loading }: Props) {
const avatar = useMemo(() => {
const id = computeAvatarId(user)
return <Avatar id={id} />
}, [user])
if (loading) return <Skeleton />
return <div>{avatar}</div>
}
```
**Correct (skips computation when loading):**
```tsx
const UserAvatar = memo(function UserAvatar({ user }: { user: User }) {
const id = useMemo(() => computeAvatarId(user), [user])
return <Avatar id={id} />
})
function Profile({ user, loading }: Props) {
if (loading) return <Skeleton />
return (
<div>
<UserAvatar user={user} />
</div>
)
}
```
**Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, manual memoization with `memo()` and `useMemo()` is not necessary. The compiler automatically optimizes re-renders.
© tech-leads-club · MIT · tech-leads-club/agent-skills