Skip to main content
rule CX Codex

rerender-derived-state-no-effect — Claude Code rule: install

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.

MIT ★ 7,191 updated 2026-10-24

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

What rerender-derived-state-no-effect does

The rule says to calculate a value during render when current props or state already provide everything needed for it. A value such as fullName should come from firstName and lastName, rather than live in a second state variable updated by useEffect. That keeps the component from adding a synchronization step for data it already has.

It also rejects effects whose sole job is to update state after props change. Use a derived value instead, or reset through a key when the component needs that behavior. If a value depends only on current props or state, storing it separately creates a second place that can drift.

What it helps with

  • spot derived values stored in React state
  • replace prop-sync effects with render-time calculations
  • remove an extra render after props change
  • prevent state from drifting away from its source values

Example prompts for the agent

  • Review this React component with rerender-derived-state-no-effect and find state that can be derived.
  • Rewrite the fullName logic so it is calculated during render instead of updated in useEffect.
  • Check whether this prop change needs a keyed reset rather than a state update inside an effect.

How to install rerender-derived-state-no-effect

Manually: put the files in place

.claude/rules/rerender-derived-state-no-effect.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-derived-state-no-effect

How do I install rerender-derived-state-no-effect in Claude Code?

Create the rule file at .claude/rules/rerender-derived-state-no-effect.md and place the rule content there.

What does rerender-derived-state-no-effect do?

It guides Claude Code away from storing values that can be calculated from current props or state. It also flags effects that update state only to mirror prop changes.

Why should fullName not be updated in useEffect?

That pattern adds a second state value and a synchronization step for data already available in firstName and lastName. Calculating it during render keeps the value tied to the current inputs.

Source text

rerender-derived-state-no-effect.md · MIT
---
title: Calculate Derived State During Rendering
impact: MEDIUM
impactDescription: avoids redundant renders and state drift
tags: rerender, derived-state, useEffect, state
---

## Calculate Derived State During Rendering

If a value can be computed from current props/state, do not store it in state or update it in an effect. Derive it during render to avoid extra renders and state drift. Do not set state in effects solely in response to prop changes; prefer derived values or keyed resets instead.

**Incorrect (redundant state and effect):**

```tsx
function Form() {
  const [firstName, setFirstName] = useState('First')
  const [lastName, setLastName] = useState('Last')
  const [fullName, setFullName] = useState('')

  useEffect(() => {
    setFullName(firstName + ' ' + lastName)
  }, [firstName, lastName])

  return <p>{fullName}</p>
}
```

**Correct (derive during render):**

```tsx
function Form() {
  const [firstName, setFirstName] = useState('First')
  const [lastName, setLastName] = useState('Last')
  const fullName = firstName + ' ' + lastName

  return <p>{fullName}</p>
}
```

References: [You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)

© 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 →
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 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 server-cache-lru The server-cache-lru rule explains when React.cache() is too narrow and an LRU cache should share data between requests. Use it for sequential actions that reuse the same records. CX Codex +1 ★ 7,191repo stars advanced-event-handler-refs advanced-event-handler-refs guides Claude Code to keep event callbacks in refs or useEffectEvent, stopping React effects from re-subscribing on every render. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open