1---2name: react-native3description: Build performant cross-platform mobile apps with React Native components, navigation, and native modules.4---56# React Native Development Rules78## Component Performance9- `FlatList` for any list over 10 items — `ScrollView` with `map` loads everything in memory, FlatList virtualizes10- `keyExtractor` must return stable unique strings — using index causes bugs on reorder and deletion11- `React.memo` prevents re-renders when props unchanged — wrap pure display components12- `useCallback` for functions passed to child components — new function reference triggers child re-render13- Avoid inline styles in render — creates new object every render, extract to `StyleSheet.create`1415## State Management16- `useState` is fine for component-local state — don't add Redux/Zustand for a toggle17- Lift state to lowest common ancestor only — higher causes unnecessary re-renders18- `useMemo` for expensive computations — but don't overuse, caching has overhead19- Context re-renders all consumers on any change — split contexts by update frequency20- Avoid storing derived data in state — compute during render from source state2122## Navigation23- React Navigation is the standard — Expo Router for file-based routing in Expo projects24- Stack screens stay mounted by default — clean up subscriptions and timers in `useEffect` cleanup25- Pass serializable params only — functions and complex objects break deep linking and state persistence26- `useFocusEffect` for screen-specific side effects — runs on focus, not just mount27- `navigation.reset` for auth flows — clears back stack, prevents returning to login after sign-in2829## Styling30- `StyleSheet.create` outside component body — creates styles once, not every render31- Flexbox defaults differ from web — `flexDirection: 'column'`, no `display: flex` needed32- Dimensions in density-independent pixels — don't use pixel values from design tools directly33- `Platform.select` for platform-specific styles — cleaner than conditionals in style objects34- No CSS inheritance — text styles don't cascade, each Text needs explicit styling3536## Native Modules37- Expo modules cover most needs — avoid ejecting for common features like camera, location, notifications38- `expo-dev-client` enables native modules without full eject — best of both worlds39- React Native New Architecture (Fabric, TurboModules) is opt-in — check library compatibility before enabling40- Native crashes don't show in JS debugger — check Xcode/Android Studio logs4142## Performance Debugging43- Hermes engine should be enabled — significantly faster startup and lower memory44- `InteractionManager.runAfterInteractions` defers heavy work — keeps animations smooth45- `useNativeDriver: true` for animations — runs on UI thread, not JS thread46- `console.log` in production kills performance — remove or use `__DEV__` guard47- Flipper for debugging — network, layout, performance profiling4849## Images50- Use `resizeMode` appropriately — `cover` crops, `contain` letterboxes, `stretch` distorts51- Prefetch images for smooth UX: `Image.prefetch(url)` before displaying52- Local images need explicit dimensions — remote images can use aspect ratio if one dimension set53- SVGs via `react-native-svg` — better scaling than PNGs for icons54- Cache remote images with `react-native-fast-image` — default Image has no persistent cache5556## Common Mistakes57- `async` in `useEffect` directly — must define async function inside, then call it58- Missing `key` warnings in lists — always use unique, stable keys59- Assuming web React patterns work — no DOM, no CSS, different event system60- Forgetting cleanup in `useEffect` — subscriptions, timers, listeners leak without cleanup return61- Testing only on one platform — iOS and Android differ in behavior, test both regularly6263## Platform Differences64- Android needs explicit `overflow: 'hidden'` for border radius clipping — iOS clips by default65- Shadows: iOS uses `shadow*` props, Android uses `elevation`66- StatusBar behavior differs — test visibility and color on both platforms67- Back button is Android-only — handle with `BackHandler` or navigation listeners68- Push notifications setup differs significantly — platform-specific configuration required6970## Build & Release71- `npx react-native clean` for unexplained build failures — clears caches and derived data72- iOS: `cd ios && pod install` after adding native dependencies — often forgotten step73- Android: `cd android && ./gradlew clean` for stubborn build issues74- EAS Build (Expo) simplifies CI/CD — handles signing, versioning, submission75- Test release builds locally before submitting — development and production behavior differ