Skip to main content
rule CX Codex

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

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

What 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 useMemo alone is not enough and memo() 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.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

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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set130

The whole set →
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 async-api-routes async-api-routes prevents sequential waterfall requests in API routes and Server Actions. It instructs the assistant to launch independent promises immediately rather than chaining awaits. CX Codex +1 ★ 7,191repo stars 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 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 rerender-memo-with-default-value 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. 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

Project sponsors

Companies that keep this analytics open