Skip to main content
rule CX Codex

react-compiler-destructure-functions — Claude Code rule

react-compiler-destructure-functions is a Claude Code rule that enforces extracting hook functions early in render scope. It targets projects running the React Compiler.

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-compiler-destructure-functions.md
Open on GitHub

What react-compiler-destructure-functions does

The rule forbids calling functions by dotting into objects such as props.onSave() or router.push(). It instructs the agent to pull functions out immediately at the top level of the component or within parameter definitions.

React Compiler creates cache keys using the referenced objects. When code accesses properties via dot notation, the compiler binds to objects that mutate across renders, which invalidates memoization. Destructuring provides stable references that preserve the cache.

This guideline applies exclusively to setups with the React Compiler enabled.

What it helps with

  • prevent memoization loss under React Compiler
  • extract hook methods into stable references early
  • eliminate property access calls inside event handlers

Example prompts for the agent

  • Check SaveButton.tsx for dot-notation calls on hook objects
  • Refactor handlers to destructure functions from props and hooks early

How to install react-compiler-destructure-functions

Manually: put the files in place

.claude/rules/react-compiler-destructure-functions.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-compiler-destructure-functions

How to install react-compiler-destructure-functions in Claude Code?

Save the rule file to .claude/rules/react-compiler-destructure-functions.md in your project repository.

What does react-compiler-destructure-functions do?

It prevents object property chaining for function calls inside components. Extracting functions directly ensures React Compiler retains stable cache keys during memoization.

What is required for react-compiler-destructure-functions to work?

The project must use the React Compiler. Without the compiler active, this rule serves no purpose.

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set47

The whole set →
rendering-text-in-text-component rendering-text-in-text-component is a Claude Code rule that enforces wrapping strings in React Native Text elements. It prevents runtime crashes in mobile interfaces. CX Codex +1 ★ 88repo stars list-performance-callbacks list-performance-callbacks is a Claude Code rule for passing event handlers to list items. It applies when callbacks are used inside a list. CX Codex +1 ★ 88repo stars monorepo-native-deps-in-app monorepo-native-deps-in-app is a Claude Code rule that enforces adding native packages directly to the mobile app manifest. It prevents build failures caused by missed autolinking in monorepos. CX Codex +1 ★ 88repo stars react-compiler-reanimated-shared-values react-compiler-reanimated-shared-values is a Claude Code rule for handling Reanimated shared values with React Compiler enabled. It directs code to use .get() and .set() rather than .value. CX Codex +1 ★ 88repo stars ui-scrollview-content-inset ui-scrollview-content-inset is a Claude Code rule for changing ScrollView spacing when keyboards, toolbars, or content alter the available space. CX Codex +1 ★ 88repo stars monorepo-single-dependency-versions monorepo-single-dependency-versions is a Claude Code rule that pins identical dependency versions across monorepo packages. It stops bundle bloat and runtime version clashes. CX Codex +1 ★ 88repo stars animation-derived-value animation-derived-value is a Claude Code rule for computing one animated shared value from another. It applies to React Native Reanimated code that derives values. CX Codex +1 ★ 88repo stars fonts-config-plugin fonts-config-plugin is a Claude Code rule that embeds Expo fonts at build time. It directs the assistant to configure the expo-font plugin instead of runtime loaders. CX Codex +1 ★ 88repo stars

Project sponsors

Companies that keep this analytics open