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
.claude/rules/react-compiler-destructure-functions.mdWhat 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.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-compiler-destructure-functions.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/react-compiler-destructure-functions.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/react-compiler-destructure-functions.mdManually: put the files in place
.clinerules/react-compiler-destructure-functions.mdStep 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.