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
.claude/rules/rerender-derived-state-no-effect.mdWhat 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-effectand find state that can be derived. - Rewrite the
fullNamelogic so it is calculated during render instead of updated inuseEffect. - 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.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-derived-state-no-effect.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/rerender-derived-state-no-effect.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/rerender-derived-state-no-effect.mdManually: put the files in place
.clinerules/rerender-derived-state-no-effect.mdStep 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