Skip to main content
rule CX Codex

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

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

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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set47

The whole set →
ui-safe-area-scroll ui-safe-area-scroll is a Claude Code rule that enforces native iOS safe area handling in React Native ScrollViews. It stops layout jumping during keyboard transitions. CX Codex +1 ★ 88repo stars design-system-compound-components design-system-compound-components is a Claude Code rule that forbids raw string children in non-text components. It enforces compound structures like ButtonText and ButtonIcon across the design system. CX Codex +1 ★ 88repo stars ui-expo-image ui-expo-image is a Claude Code rule that swaps React Native's default Image for expo-image. It guides code generation toward blurhash placeholders, disk caching, and list recycling. CX Codex +1 ★ 88repo stars js-hoist-intl js-hoist-intl is a Claude Code rule that moves Intl formatter creation out of renders and loops. It applies to JavaScript code that formats dates, numbers, or relative time. CX Codex +1 ★ 88repo stars list-performance-virtualize list-performance-virtualize is a Claude Code rule that recommends virtualized lists for scrollable content. It applies while building list-based screens. CX Codex +1 ★ 88repo stars react-state-minimize react-state-minimize is a Claude Code rule that enforces minimal React state. It directs assistants to compute values on render rather than storing redundant state variables. CX Codex +1 ★ 88repo stars rendering-no-falsy-and rendering-no-falsy-and is a Claude Code rule that guards against unsafe conditional JSX rendering. It targets cases where a value may be an empty string or zero. CX Codex +1 ★ 88repo stars ui-native-modals ui-native-modals is a Claude Code rule that directs coding assistants to use native React Native modal elements instead of JavaScript-based bottom sheet packages. CX Codex +1 ★ 88repo stars

Project sponsors

Companies that keep this analytics open