Chuyển đến nội dung
Skillpedia
Ứng dụng di động280k · #236

react-native-patterns

Skill này làm gì

Hướng dẫn này chỉ cách tổ chức và xây dựng ứng dụng di động bằng React Native và Expo. Nó trình bày thực hành tốt nhất về điều hướng, quản lý dữ liệu, hiển thị danh sách, kiểu dáng và sử dụng các tính năng của điện thoại.

Khi nào nên dùng

  • ✓Khi tạo màn hình hoặc thành phần mới trong ứng dụng React Native.
  • ✓Khi thiết lập cách người dùng di chuyển giữa các màn hình.
  • ✓Khi quyết định cách lưu trữ và lấy thông tin trong ứng dụng.

Liên kết skill

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/react-native-patterns/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/react-native-patterns/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để tổ chức điều hướng giữa các màn hình ứng dụng React Native của tôi bằng Expo Router?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Hướng dẫn gợi ý dùng Expo Router để tổ chức màn hình theo tệp, trong đó cấu trúc thư mục xác định điều hướng. Nó cũng giải thích cách tách các loại dữ liệu (từ máy chủ, phía client, biểu mẫu) và lấy dữ liệu hiệu quả bằng các thư viện như TanStack Query.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

React Native / Expo Patterns

Practical patterns for building production React Native apps with Expo. Covers navigation, state, data fetching, lists, styling, and native APIs. Pairs with the rules/react-native/ ruleset: rules say what to enforce, this skill shows how.

Libraries named below (NativeWind, Zustand/Jotai, TanStack Query) are common, well-established options shown for illustration — the patterns matter more than the specific package, and any equivalent works. Zod is used for validation to stay consistent with ECC's existing typescript/ rules.

These patterns assume the managed Expo workflow (Expo Router, EAS, expo-* modules) on the New Architecture (the default in recent Expo SDKs, mandatory from SDK 55+). They do NOT assume the browser DOM — React Native has no <div>, no URL bar, and no web data-fetching defaults.

When to Activate

Use this skill when:

  • Building or editing React Native / Expo screens, components, or navigation
  • Setting up routing with Expo Router (file-based app/ directory)
  • Deciding where state belongs (server cache vs client store vs route params vs form)
  • Wiring data fetching with TanStack Query and validating responses with Zod
  • Rendering long or heavy lists
  • Choosing or applying a styling approach (NativeWind or StyleSheet)
  • Accessing native device APIs (camera, location, notifications) or secure storage
  • Reviewing RN code for mobile-specific issues

Do NOT use the web/React-DOM patterns here — URL-as-state, <div>, and SWR-for-browser do not apply to React Native.

Core Concepts

Project structure (Expo Router)

File-based routing under app/. Keep route files thin: they read and validate params, then delegate to a screen component that lives in components/ or features/.

app/
  _layout.tsx          # root stack
  (tabs)/
    _layout.tsx        # tab navigator
    index.tsx          # Home
  user/[id].tsx        # dynamic route
components/
features/
  user/UserProfile.tsx

Navigation: validate route params

Deep links and dynamic routes deliver untrusted strings. Validate them with Zod before use.

// app/user/[id].tsx
import { useLocalSearchParams, router } from 'expo-router'
import { z } from 'zod'
import { UserProfile } from '@/features/user/UserProfile'

const Params = z.object({ id: z.string().uuid() })

export default function UserRoute() {
  const parsed = Params.safeParse(useLocalSearchParams())
  if (!parsed.success) {
    router.replace('/not-found')
    return null
  }
  return <UserProfile userId={parsed.data.id} />
}

State: keep concerns separate

Do not duplicate server data into a client store. Each concern has its own home.

Concern Common choices
Server state (remote data) a server-cache library (TanStack Query, SWR)
Client/UI state a lightweight store (Zustand, Jotai) or Context
Route/navigation state Expo Router params
Form state a form library (e.g. React Hook Form) + schema validation
Secrets / tokens expo-secure-store
Non-secret persistence AsyncStorage / MMKV

Prefer local useState until state genuinely needs sharing.

Data fetching: a cache library + Zod

Use a server-cache library (TanStack Query, SWR) instead of fetch-in-useEffect. Validate at the boundary and infer types from the schema. Handle loading, error, and empty states explicitly. (Example uses TanStack Query.)

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { z } from 'zod'

const User = z.object({ id: z.string(), email: z.string().email() })
type User = z.infer<typeof User>

export function useUser(id: string) {
  return useQuery({
    queryKey: ['user', id],
    queryFn: async (): Promise<User> => User.parse(await api.getUser(id)),
  })
}

export function useUpdateEmail(id: string) {
  const qc = useQueryClient()
  return useMutation({
    mutationFn: (email: string) => api.updateEmail(id, email),
    onSuccess: () => qc.invalidateQueries({ queryKey: ['user', id] }),
  })
}

Lists: virtualize, never map a big array in a ScrollView

import { FlatList } from 'react-native'

<FlatList
  data={items}
  keyExtractor={(item) => item.id}
  renderItem={renderItem}          // memoized
  initialNumToRender={10}
  windowSize={5}
/>

Use FlashList (Shopify) for large or heterogeneous lists.

Styling: pick one system

…

Câu hỏi thường gặp

Expo Router là gì?

Đây là cách tổ chức màn hình ứng dụng React Native theo tệp, trong đó cấu trúc thư mục xác định điều hướng.

Vì sao phải tách các loại dữ liệu?

Tách dữ liệu giúp code có tổ chức và tránh việc thông tin từ máy chủ bị sao chép không cần thiết trong ứng dụng.

Làm sao để hiển thị danh sách dài một cách hiệu quả?

Hướng dẫn khuyến nghị dùng kỹ thuật 'virtualization' với các thành phần như FlatList, để ứng dụng không bị chậm khi hiển thị nhiều mục.

Chi tiết

Mô tả gốc của tác giả

React Native and Expo app patterns — Expo Router navigation, state separation (server/client/route/form), TanStack Query data fetching with Zod, performant lists, NativeWind/StyleSheet styling, native APIs, and secure storage. Use when building or editing React Native / Expo screens, components, navigation, or data layers.

repo: affaan-m/ECC

Độ phổ biến

Sao GitHub
280k
Vị trí xếp hạng
#236
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự