๐ค
React Native
Build performant cross-platform mobile apps with React Native components, navigation, and native modules.
ๅฎๅ
จ้่ฟ
๐ฌPrompt
ๆ่ฝ่ฏดๆ
name: React Native description: Build performant cross-platform mobile apps with React Native components, navigation, and native modules. metadata: {"clawdbot":{"emoji":"๐ฑ","requires":{"anyBins":["npx","expo"]},"os":["linux","darwin","win32"]}}
React Native Development Rules
Component Performance
FlatListfor any list over 10 items โScrollViewwithmaploads everything in memory, FlatList virtualizeskeyExtractormust return stable unique strings โ using index causes bugs on reorder and deletionReact.memoprevents re-renders when props unchanged โ wrap pure display componentsuseCallbackfor functions passed to child components โ new function reference triggers child re-render- Avoid inline styles in render โ creates new object every render, extract to
StyleSheet.create
State Management
useStateis fine for component-local state โ don't add Redux/Zustand for a toggle- Lift state to lowest common ancestor only โ higher causes unnecessary re-renders
useMemofor expensive computations โ but don't overuse, caching has overhead- Context re-renders all consumers on any change โ split contexts by update frequency
- Avoid storing derived data in state โ compute during render from source state
Navigation
- React Navigation is the standard โ Expo Router for file-based routing in Expo projects
- Stack screens stay mounted by default โ clean up subscriptions and timers in
useEffectcleanup - Pass serializable params only โ functions and complex objects break deep linking and state persistence
useFocusEffectfor screen-specific side effects โ runs on focus, not just mountnavigation.resetfor auth flows โ clears back stack, prevents returning to login after sign-in
Styling
StyleSheet.createoutside component body โ creates styles once, not every render- Flexbox defaults differ from web โ
flexDirection: 'column', nodisplay: flexneeded - Dimensions in density-independent pixels โ don't use pixel values from design tools directly
Platform.selectfor platform-specific styles โ cleaner than conditionals in style objects- No CSS inheritance โ text styles don't cascade, each Text needs explicit styling
Native Modules
- Expo modules cover most needs โ avoid ejecting for common features like camera, location, notifications
expo-dev-clientenables native modules without full eject โ best of both worlds- React Native New Architecture (Fabric, TurboModules) is opt-in โ check library compatibility before enabling
- Native crashes don't show in JS debugger โ check Xcode/Android Studio logs
Performance Debugging
- Hermes engine should be enabled โ significantly faster startup and lower memory
InteractionManager.runAfterInteractionsdefers heavy work โ keeps animations smoothuseNativeDriver: truefor animations โ runs on UI thread, not JS threadconsole.login production kills performance โ remove or use__DEV__guard- Flipper for debugging โ network, layout, performance profiling
Images
- Use
resizeModeappropriately โcovercrops,containletterboxes,stretchdistorts - Prefetch images for smooth UX:
Image.prefetch(url)before displaying - Local images need explicit dimensions โ remote images can use aspect ratio if one dimension set
- SVGs via
react-native-svgโ better scaling than PNGs for icons - Cache remote images with
react-native-fast-imageโ default Image has no persistent cache
Common Mistakes
asyncinuseEffectdirectly โ must define async function inside, then call it- Missing
keywarnings in lists โ always use unique, stable keys - Assuming web React patterns work โ no DOM, no CSS, different event system
- Forgetting cleanup in
useEffectโ subscriptions, timers, listeners leak without cleanup return - Testing only on one platform โ iOS and Android differ in behavior, test both regularly
Platform Differences
- Android needs explicit
overflow: 'hidden'for border radius clipping โ iOS clips by default - Shadows: iOS uses
shadow*props, Android useselevation - StatusBar behavior differs โ test visibility and color on both platforms
- Back button is Android-only โ handle with
BackHandleror navigation listeners - Push notifications setup differs significantly โ platform-specific configuration required
Build & Release
npx react-native cleanfor unexplained build failures โ clears caches and derived data- iOS:
cd ios && pod installafter adding native dependencies โ often forgotten step - Android:
cd android && ./gradlew cleanfor stubborn build issues - EAS Build (Expo) simplifies CI/CD โ handles signing, versioning, submission
- Test release builds locally before submitting โ development and production behavior differ
ๅฆไฝไฝฟ็จใReact Nativeใ๏ผ
- ๆๅผๅฐ้พ่พAI๏ผWeb ๆ iOS App๏ผ
- ็นๅปไธๆนใ็ซๅณไฝฟ็จใๆ้ฎ๏ผๆๅจๅฏน่ฏๆกไธญ่พๅ ฅไปปๅกๆ่ฟฐ
- ๅฐ้พ่พAI ไผ่ชๅจๅน้ ๅนถ่ฐ็จใReact Nativeใๆ่ฝๅฎๆไปปๅก
- ็ปๆๅณๆถๅ็ฐ๏ผๆฏๆ็ปง็ปญๅฏน่ฏไผๅ