All skills
Skillintermediate
react compiler destructure functions
This rule is only applicable if you are using the React Compiler.
Claude Code Knowledge Pack7/10/2026
Overview
Destructure Functions Early in Render
This rule is only applicable if you are using the React Compiler.
Destructure functions from hooks at the top of render scope. Never dot into objects to call functions. Destructured functions are stable references; dotting creates new references and breaks memoization.
Incorrect (dotting into object):
function SaveButton(props) {
const router = useRouter()
// bad: react-compiler will key the cache on "props" and "router", which are objects that change each render
const handlePress = () => {
props.onSave()
router.push('/success') // unstable reference
}
return Save
}
Correct (destructure early):
function SaveButton({ onSave }) {
const { push } = useRouter()
// good: react-compiler will key on push and onSave
const handlePress = () => {
onSave()
push('/success') // stable reference
}
return Save
}