react-state-fallback — Claude Code rule: what it does, how to install
react-state-fallback is a Claude Code rule that enforces reactive fallbacks instead of copying props into component state. It prevents stale UI bugs during parent updates.
AGPL-3.0 ★ 88 updated 2026-11-17
.claude/rules/react-state-fallback.mdWhat react-state-fallback does
The rule instructs the assistant to set undefined inside useState calls and resolve active values with nullish coalescing against incoming props. State then represents deliberate user overrides rather than a duplicate store for defaults.
When a parent component passes fresh data or a query refetches, the UI updates immediately. The field remains linked to the source until an interaction occurs. Once the user alters the input, their specific choice persists.
The project is released under the AGPL-3.0 license. Configuration lives in .claude/rules/react-state-fallback.md for Claude Code or .cursor/rules/react-state-fallback.mdc when targeting Cursor.
What it helps with
- keep component interfaces reactive to parent prop changes
- prevent stale form fields after background data refetches
- isolate explicit user overrides from fallback defaults
Example prompts for the agent
- Generate a toggle component that tracks user choice but falls back to parent props
- Refactor this form to stop copying initial server data into useState
How to install react-state-fallback
Manually: put the files in place
.claude/rules/react-state-fallback.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/react-state-fallback.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/react-state-fallback.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/react-state-fallback.mdManually: put the files in place
.clinerules/react-state-fallback.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about react-state-fallback
How to install react-state-fallback in Claude Code?
Save the rule file into your project at .claude/rules/react-state-fallback.md.
What does react-state-fallback do?
It directs coding assistants to initialize state hooks with undefined and fall back to incoming props via ??. This keeps local fields synchronized with upstream updates until edited.
Why not pass the prop directly into useState?
Direct arguments to useState evaluate only during initial mounting. Using undefined alongside ?? allows the component to pick up new prop values automatically on subsequent renders.