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