# react-state-fallback

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.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 88 repo stars
- Author: alexj11324
- License: AGPL-3.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/alexj11324/Mikka/tree/HEAD/.claude/skills/react-native-skills/rules/react-state-fallback.md
- Updated: 2026-11-17
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/react-state-fallback

## What it 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.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/rules/react-state-fallback.md` — The paths frontmatter field limits the files

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### Cursor

**Manually: put the files in place**
- File: `.cursor/rules/react-state-fallback.mdc` — Frontmatter: description, globs, alwaysApply

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/react-state-fallback.instructions.md` — The applyTo field sets which files it applies to

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/react-state-fallback.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/react-state-fallback.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/alexj11324/Mikka/tree/HEAD/.claude/skills/react-native-skills/rules/react-state-fallback.md

## When to use it
- 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
- 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

## Similar
- [zustand-state-management](https://affpapa.org/en/nevibecode/skills/zustand-state-management.md) — skill · 1000 installs
- [state-decouple-implementation](https://affpapa.org/en/nevibecode/rules/state-decouple-implementation.md) — rule · ★ 7191 repo stars
- [React State Management taste](https://affpapa.org/en/nevibecode/prompts/react-state-management-taste.md) — prompt · ★ 178201 repo stars
- [state-management](https://affpapa.org/en/nevibecode/skills/state-management.md) — skill · 849 installs
- [frontend-state-management](https://affpapa.org/en/nevibecode/skills/frontend-state-management.md) — skill · 487 installs
- [react-state-dispatcher](https://affpapa.org/en/nevibecode/rules/react-state-dispatcher.md) — rule · ★ 1216 repo stars

From the same set: [alexj11324/mikka](https://affpapa.org/en/nevibecode/by/alexj11324/mikka.md) — 47 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
