1---2name: react-native3description: Build performant cross-platform mobile apps with React Native components, navigation, and native modules.4---5
6# React Native Development Rules
7
8## Component Performance
9- `FlatList` for any list over 10 items — `ScrollView` with `map` loads everything in memory, FlatList virtualizes
10- `keyExtractor` must return stable unique strings — using index causes bugs on reorder and deletion
11- `React.memo` prevents re-renders when props unchanged — wrap pure display components
12- `useCallback` for functions passed to child components — new function reference triggers child re-render
13- Avoid inline styles in render — creates new object every render, extract to `StyleSheet.create`
14
15## State Management
16- `useState` is fine for component-local state — don't add Redux/Zustand for a toggle
17- Lift state to lowest common ancestor only — higher causes unnecessary re-renders
18- `useMemo` for expensive computations — but don't overuse, caching has overhead
19- Context re-renders all consumers on any change — split contexts by update frequency
20- Avoid storing derived data in state — compute during render from source state
21
22## Navigation
23- React Navigation is the standard — Expo Router for file-based routing in Expo projects
24- Stack screens stay mounted by default — clean up subscriptions and timers in `useEffect` cleanup
25- Pass serializable params only — functions and complex objects break deep linking and state persistence
26- `useFocusEffect` for screen-specific side effects — runs on focus, not just mount
27- `navigation.reset` for auth flows — clears back stack, prevents returning to login after sign-in
28
29## Styling
30- `StyleSheet.create` outside component body — creates styles once, not every render
31- Flexbox defaults differ from web — `flexDirection: 'column'`, no `display: flex` needed
32- Dimensions in density-independent pixels — don't use pixel values from design tools directly
33- `Platform.select` for platform-specific styles — cleaner than conditionals in style objects
34- No CSS inheritance — text styles don't cascade, each Text needs explicit styling
35
36## Native Modules
37- Expo modules cover most needs — avoid ejecting for common features like camera, location, notifications
38- `expo-dev-client` enables native modules without full eject — best of both worlds
39- React Native New Architecture (Fabric, TurboModules) is opt-in — check library compatibility before enabling
40- Native crashes don't show in JS debugger — check Xcode/Android Studio logs
41
42## Performance Debugging
43- Hermes engine should be enabled — significantly faster startup and lower memory
44- `InteractionManager.runAfterInteractions` defers heavy work — keeps animations smooth
45- `useNativeDriver: true` for animations — runs on UI thread, not JS thread
46- `console.log` in production kills performance — remove or use `__DEV__` guard
47- Flipper for debugging — network, layout, performance profiling
48
49## Images
50- Use `resizeMode` appropriately — `cover` crops, `contain` letterboxes, `stretch` distorts
51- Prefetch images for smooth UX: `Image.prefetch(url)` before displaying
52- Local images need explicit dimensions — remote images can use aspect ratio if one dimension set
53- SVGs via `react-native-svg` — better scaling than PNGs for icons
54- Cache remote images with `react-native-fast-image` — default Image has no persistent cache
55
56## Common Mistakes
57- `async` in `useEffect` directly — must define async function inside, then call it
58- Missing `key` warnings in lists — always use unique, stable keys
59- Assuming web React patterns work — no DOM, no CSS, different event system
60- Forgetting cleanup in `useEffect` — subscriptions, timers, listeners leak without cleanup return
61- Testing only on one platform — iOS and Android differ in behavior, test both regularly
62
63## Platform Differences
64- Android needs explicit `overflow: 'hidden'` for border radius clipping — iOS clips by default
65- Shadows: iOS uses `shadow*` props, Android uses `elevation`
66- StatusBar behavior differs — test visibility and color on both platforms
67- Back button is Android-only — handle with `BackHandler` or navigation listeners
68- Push notifications setup differs significantly — platform-specific configuration required
69
70## Build & Release
71- `npx react-native clean` for unexplained build failures — clears caches and derived data
72- iOS: `cd ios && pod install` after adding native dependencies — often forgotten step
73- Android: `cd android && ./gradlew clean` for stubborn build issues
74- EAS Build (Expo) simplifies CI/CD — handles signing, versioning, submission
75- Test release builds locally before submitting — development and production behavior differ