react-native-patterns
できること
React NativeとExpoを使ってモバイルアプリを整理して作る方法を解説します。画面遷移、データ管理、リストの表示、スタイリング、スマートフォンの機能の利用など、ベストプラクティスを紹介します。
使う場面
- ✓React Nativeアプリで新しい画面やコンポーネントを作るとき。
- ✓ユーザーがアプリの画面間を移動する仕組みを設定するとき。
- ✓アプリで情報をどのように保存・取得するかを決めるとき。
スキルのリンク
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/react-native-patterns/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Expo Routerを使って、React Nativeアプリの画面間の移動をどのように整理できますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このガイドでは、Expo Routerを使って、ファイルごとに画面を整理する方法を提案します。また、データの種類(サーバー由来、クライアント由来、フォーム入力など)を分ける方法や、TanStack Queryなどのライブラリを使って効率よくデータを取得する方法も説明します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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
…
よくある質問
Expo Routerとは何ですか?
React Nativeアプリの画面をファイル単位で整理する仕組みです。フォルダの構造がそのまま画面遷移を決めます。
データを分ける理由は何ですか?
データを分けることで、コードが整理されやすくなり、サーバーの情報をアプリ内で不必要に複製することを防げます。
長いリストを効率よく表示するにはどうすればよいですか?
FlatListなどのコンポーネントを使い、「仮想化」と呼ばれる手法を用いることを勧めています。これにより、多くの項目を表示してもアプリの動作が遅くなりにくくなります。
詳細
作者による元の説明
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
人気
- GitHubのスター
- 280k
- ランキング
- #236
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
accessibility
280kエージェントが誰にとっても使いやすいインターフェースを作れるように手助けします。目が見えない方や身体の動きに制限のある方など、障害のある人にとってもWebサイトやアプリが正しく動くようにします。
agent-architecture-audit
280kエージェントがすべて正しく動いているかを確認できるようにします。AIシステムの問題を見つけて修正し、期待どおりに動くようにします。
agent-eval
280kエージェントが異なるAIコーディングツールを比較できるようにします。特定のタスクにおいて、どれがより速く、安く、信頼性が高いかを測定します。
agent-harness-construction
280kエージェントがタスクの進め方をよりよく理解できるようにします。エージェントが使うツールや指示を最適化し、成功する可能性を高めます。
似ているスキル
flutter-animating-apps
101kFlutterアプリにアニメーション効果やトランジションを追加できるようにします。iOSやAndroidアプリで動きやビジュアルデザインを作るのに役立ちます。
agent-spec-mobile-react-native
81kReact Nativeで、iPhoneとAndroidのモバイルアプリを、画面、ナビゲーション、ネイティブモジュールを含めて作る手助けをします。
orientation
75kエージェントが縦向きと横向きの両方でサイトが機能するようにし、画面の向きの固定や「端末を回転させてください」という表示を取り除いて、人々がコンテンツを見られるようにします。