Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/react-compiler-destructure-functions.md
1---2title: Destructure Functions Early in Render (React Compiler)3impact: HIGH4impactDescription: stable references, fewer re-renders5tags: rerender, hooks, performance, react-compiler6---78## Destructure Functions Early in Render910This rule is only applicable if you are using the React Compiler.1112Destructure functions from hooks at the top of render scope. Never dot into13objects to call functions. Destructured functions are stable references; dotting14creates new references and breaks memoization.1516**Incorrect (dotting into object):**1718```tsx19import { useRouter } from 'expo-router'2021function SaveButton(props) {22const router = useRouter()2324// bad: react-compiler will key the cache on "props" and "router", which are objects that change each render25const handlePress = () => {26props.onSave()27router.push('/success') // unstable reference28}2930return <Button onPress={handlePress}>Save</Button>31}32```3334**Correct (destructure early):**3536```tsx37import { useRouter } from 'expo-router'3839function SaveButton({ onSave }) {40const { push } = useRouter()4142// good: react-compiler will key on push and onSave43const handlePress = () => {44onSave()45push('/success') // stable reference46}4748return <Button onPress={handlePress}>Save</Button>49}50```51