Communityコーディング&開発github.com

react-native-best-practices

React Nativeアプリケーションのパフォーマンス最適化に関するガイドラインを提供します。FPS、TTI、バンドルサイズ、メモリリーク、再レンダリング、アニメーションなどをカバーし、Hermes最適化、JSスレッドブロッキング、ブリッジオーバーヘッド、FlashList、ネイティブモジュール、ジャンクやフレームドロップのデバッグなどに関連するタスクに適用します。

react-native-best-practices とは?

このスキルは、React Nativeアプリケーションのパフォーマンス最適化のための包括的なガイドラインを提供します。Callstack社の「The Ultimate Guide to React Native Optimization」に基づいており、JavaScript/React、ネイティブ(iOS/Android)、バンドル最適化の3つの主要領域をカバーします。FPS低下やアニメーションのジャンク、メモリリーク、アプリ起動時間(TTI)、バンドルサイズ肥大化など、一般的なパフォーマンス問題に対して優先順位付けされた解決策を提示します。各ガイドラインは具体的なファイルリファレンスにリンクされており、問題の種類に応じて「問題→スキルマッピング」テーブルから適切なドキュメントにアクセスできます。また、測定→最適化→再測定→検証という反復的なワークフローを推奨し、プロファイリング結果に基づいたデータ駆動型の最適化を重視します。特に`agent-device react-devtools`コマンドを使用したReactコンポーネントのプロファイリング、FlashListやReact Compiler、Jotai/Zustandなどのパフォーマンス改善技術を具体的に解説しており、React Nativeアプリの開発者にとって実践的なリファレンスとなります。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/callstackincubator/agent-skills/tree/main/skills/react-native-best-practices

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

React Native ベストプラクティス

概要

React Nativeアプリケーションのパフォーマンス最適化ガイドです。JavaScript/React、ネイティブ(iOS/Android)、バンドル化の最適化をカバーします。Callstack社の「Ultimate Guide to React Native Optimization」に基づいています。

適用タイミング

以下の場合にこれらのガイドラインを参照してください:

  • 遅い/ジャンキーなUIやアニメーションのデバッグ
  • メモリリークの調査(JS側またはネイティブ側)
  • アプリ起動時間(TTI)の最適化
  • バンドルサイズまたはアプリサイズの削減
  • ネイティブモジュール(Turbo Modules)の作成
  • React Nativeのパフォーマンスプロファイリング
  • パフォーマンスの観点からのReact Nativeコードレビュー

セキュリティ注意事項

  • ここで参照するシェルコマンドは、ローカルの開発者操作として扱ってください。実行前に内容を確認し、バージョン固定のツールを優先し、リモートスクリプトをシェルに直接パイプしないでください。
  • サードパーティのライブラリやプラグインは、通常のサプライチェーン管理が必要な依存関係として扱ってください。バージョンを固定し、出所を確認し、標準的なレビュープロセスを通じて更新してください。
  • リモートチャンクの読み込みは、自社製のアーティファクト配信のみとして扱ってください。アプリにバンドルされたチャンクまたは署名されたCIリリースマニフェストを優先し、ホストされるチャンクは、自社管理の信頼できるHTTPSオリジンから提供され、現在のアプリリリースに固定されている必要があります。

優先順位付けされたガイドライン

優先度カテゴリ影響プレフィックス
1FPSと再レンダリングCRITICALjs-*
2バンドルサイズCRITICALbundle-*
3TTI最適化HIGHnative-*, bundle-*
4ネイティブパフォーマンスHIGHnative-*
5メモリ管理MEDIUM-HIGHjs-*, native-*
6アニメーションMEDIUMjs-*

影響ラベルはトリアージのヒントです:CRITICALを最初に、次にHIGH、そして証拠が示す場合にMEDIUMを確認してください。

クイックリファレンス

最適化ワークフロー

パフォーマンス問題が発生した場合は、次のサイクルに従ってください:測定 → 最適化 → 再測定 → 検証

  1. 測定:変更前のベースラインメトリクスを取得します。ランタイムの問題については、コミットタイムライン、再レンダリング回数、低速コンポーネント、最もコストのかかるコミットの内訳、起動時間/TTI(利用可能な場合)を優先してください。コンポーネントツリーの深さや数は代替情報ではなく、あくまでオプションのコンテキストです。測定されたレンダリングやFPSの問題がない限り、メモ化、アトミックステート、コンパイラの変更を推奨しないでください。
  2. 最適化:該当するリファレンスからターゲットを絞った修正を適用します。
  3. 再測定:同じ測定を実行し、更新されたメトリクスを取得します。
  4. 検証:改善を確認します(例:FPS 45→60、TTI 3.2秒→1.8秒、バンドル 2.1MB→1.6MB)。

メトリクスが改善しなかった場合は、変更を元に戻し、次の推奨修正を試してください。

レビュー時のガードレール

  • API固有の修正を提案する前に、ライブラリのバージョンを確認してください。例:FlashList v2ではestimatedItemSizeが非推奨であるため、そこで欠落しているフラグを立てないでください。
  • 動作が明らかに間違っている場合、またはプロファイリングがその値に関連する無駄な処理を示していない限り、useMemoやuseCallbackの依存関係の変更を提案しないでください。
  • 推測でクロージャの古い値(stale closure)を報告しないでください。それを指摘する前に、古い値を読み取るパス、再現手順、またはプロファイラの証拠を示してください。
  • フローをプロファイリングする際は、対象のインタラクション自体を測定してください。コンポーネントツリーの深さやコンポーネント数を主要なパフォーマンスの証拠として扱わないでください。

最重要:FPSと再レンダリング

まずプロファイリングを実行:

agent-device react-devtools status
agent-device react-devtools wait --connected
agent-device react-devtools profile start
agent-device react-devtools profile stop
agent-device react-devtools profile slow --limit 5
agent-device react-devtools profile rerenders --limit 5
agent-device react-devtools profile timeline --limit 20

profile startとprofile stopの間で、通常のagent-deviceコマンドで対象のインタラクションを操作してください。

agent-deviceが利用できない場合の手動フォールバック:Metro(j)またはデバッグメニューからReact Native DevToolsを開き、Profilerタブを使用して同じインタラクションを記録してください。

リリースビルドのReactコンポーネントプロファイリングの場合は、最初に@callstack/inspectorを接続してReact DevToolsがリリースアプリにアタッチできるようにし、その後上記のagent-device react-devtoolsフローを実行してください。

一般的な修正:

  • 長いリストに対しては、ScrollViewをFlatList/FlashList/Legend Listに置き換える
  • プロファイリングが連鎖的な再レンダリングを示した後は、React Compilerを使用して自動メモ化を行う
  • プロファイリングが広範なストア/コンテキスト更新を示した後は、アトミックステート(Jotai/Zustand)を使用して再レンダリングを削減する
  • 高コストな計算にはuseDeferredValueを使用する

最重要:バンドルサイズ

バンドルの分析:

npx react-native bundle \
  --entry-file index.js \
  --bundle-output output.js \
  --platform ios \
  --sourcemap-output output.js.map \
  --dev false --minify true

npx source-map-explorer output.js --no-border-checks

最適化後の改善の確認:

# 変更前のベースラインサイズを記録
ls -lh output.js  # 例:Before: 2.1 MB

# 修正適用後、再バンドルして比較
npx react-native bundle --entry-file index.js --bundle-output output.js \
  --platform ios --dev false --minify true
ls -lh output.js  # 例:After: 1.6 MB  (24%削減)

一般的な修正:

  • バレルインポートを避ける(ソースから直接インポートする)
  • HermesのAPIとメソッドのカバレッジを確認した後にのみ、不要なIntlポリフィルを削除する
  • ツリーシェイキングを評価する(Expo SDK 52+の実験的な未使用インポート/エクスポート削除、または既に設定されている場合のみRe.Pack)
  • Androidのネイティブコード縮小のためにR8を有効にする

高優先度:TTI最適化

TTIの測定:

  • react-native-performanceをマーカーに使用する
  • コールドスタートのみを測定する(ウォーム/ホット/プレウォームは除外する)

一般的な修正:

  • React Native 0.78以前では、AndroidのJSバンドル圧縮を無効にしてHermesのmmapを有効にする
  • ネイティブナビゲーション(react-native-screens)を使用する
  • よく使われる高コストな画面に遷移する前に、それらをプリロードする

高優先度:ネイティブパフォーマンス

ネイティブのプロファイリング:

  • iOS:Xcode Instruments → Time Profiler
  • Android:Android Studio → CPU Profiler

一般的な修正:

  • 高負荷なネイティブ処理にはバックグラウンドスレッドを使用する
  • 同期Turbo Moduleメソッドよりも非同期を優先する
  • クロスプラットフォームのパフォーマンス重視のコードにはC++を使用する

リファレンス

完全なドキュメント(コード例付き)はreferences/にあります:

JavaScript/React (js-*)

ファイル影響説明
js-lists-flatlist-flashlist.mdCRITICALScrollViewを仮想化リストに置き換え
js-profile-react.mdMEDIUMagent-device react-devtoolsプロファイリング
js-measure-fps.mdHIGHFPS監視と測定
js-memory-leaks.mdMEDIUMJSメモリリークの追跡
js-atomic-state.mdHIGHJotai/Zustandパターン
js-concurrent-react.mdHIGHuseDeferredValue, useTransition
js-react-compiler.mdHIGH自動メモ化
js-animations-reanimated.mdMEDIUMReanimatedのワークレット
js-bottomsheet.mdHIGHボトムシートの最適化
js-uncontrolled-components.mdHIGHTextInputの最適化

ネイティブ (native-*)

ファイル影響説明
native-turbo-modules.mdHIGH高速なネイティブモジュールの構築
native-sdks-over-polyfills.mdHIGHネイティブライブラリ vs JSライブラリ
native-measure-tti.mdHIGHTTI測定のセットアップ
native-threading-model.mdHIGHTurbo Moduleのスレッド
native-profiling.mdMEDIUMXcode/Android Studioでのプロファイリング
native-platform-setup.mdMEDIUMiOS/Androidツールガイド
native-view-flattening.mdMEDIUMビュー階層のデバッグ
native-memory-patterns.mdMEDIUMC++/Swift/Kotlinのメモリ
native-memory-leaks.mdMEDIUMネイティブメモリリークの追跡
native-android-16kb-alignment.mdCRITICALGoogle Play向けサードパーティライブラリアライメント

バンドル (bundle-*)

ファイル影響説明
bundle-barrel-exports.mdCRITICALバレルインポートを避ける
bundle-analyze-js.mdCRITICALJSバンドルの可視化
bundle-tree-shaking.mdHIGHデッドコードの除去
bundle-analyze-app.mdHIGHアプリサイズの分析
bundle-r8-android.mdHIGHAndroidコードの縮小
bundle-hermes-mmap.mdHIGHバンドル圧縮の無効化
bundle-native-assets.mdHIGHアセットカタログのセットアップ
bundle-library-size.mdMEDIUM依存関係の評価
bundle-code-splitting.mdMEDIUMリモートチャンク読み込みのセキュリティ対策

問題 → スキルマッピング

問題最初に参照するもの
アプリが遅い/ジャンキーjs-measure-fps.md → js-profile-react.md
再レンダリングが多すぎるjs-profile-react.md → js-react-compiler.md
起動が遅い(TTI)native-measure-tti.md → bundle-analyze-js.md
アプリサイズが大きいbundle-analyze-app.md → bundle-r8-android.md
メモリが増加しているjs-memory-leaks.md または native-memory-leaks.md
アニメーションがフレームをドロップするjs-animations-reanimated.md
ボトムシートがジャンキー/再レンダリングjs-bottomsheet.md → js-animations-reanimated.md
リストスクロールがジャンキーjs-lists-flatlist-flashlist.md
TextInputの遅延js-uncontrolled-components.md
ネイティブモジュールが遅いnative-turbo-modules.md → native-threading-model.md
ネイティブライブラリアライメントの問題native-android-16kb-alignment.md

帰属

Callstack社の「The Ultimate Guide to React Native Optimization」に基づいています。

Individual skills in this repo

This repo contains 15 individual skills — each has its own dedicated page.

agent-device

Automates interactions for Apple-platform apps (iOS, tvOS, macOS) and Android devices. Use when navigating apps, taking snapshots/screenshots, tapping, typing, scrolling, or extracting UI info across mobile, TV, and desktop targets.

assess-react-native-migration

Assesses whether and how an existing mobile product should migrate to React Native. Use when auditing one or more product repositories for migration readiness, including products whose iOS, Android, and other clients live in separate directories or repositories; choosing brownfield, greenfield, or a checkpoint-based path; defining a representative trial; or preparing a baseline and ROI decision before implementation. When product scope or material evidence is unavailable, grills the stakeholder with exactly one question per turn instead of sending a questionnaire.

callstackincubator/github

GitHub patterns using gh CLI for pull requests, stacked PRs, code review, branching strategies, and repository automation. Use when working with GitHub PRs, merging strategies, or repository management tasks.

callstackincubator/validate-skills

Validates skills in this repo against agentskills.io spec and Claude Code best practices. Use via /validate-skills command.

create-react-native-library

Scaffolds React Native libraries with create-react-native-library for standalone libraries or local native modules and views. Use when creating or working on React Native libraries or adding native functionality in an existing app.

dogfood

Systematically explore and test a mobile app on iOS/Android with agent-device to find bugs, UX issues, and other problems. Use when asked to "dogfood", "QA", "exploratory test", "find issues", "bug hunt", or "test this app" on mobile. Produces a structured report with reproducible evidence: screenshots, optional repro videos, and detailed steps for every issue.

github-actions

GitHub Actions workflow patterns for React Native iOS simulator and Android emulator cloud builds with downloadable artifacts. Use when setting up CI build pipelines or downloading GitHub Actions artifacts via gh CLI and GitHub API.

react-native-brownfield-migration

Implements an accepted incremental brownfield migration from native iOS or Android to React Native or Expo using @callstack/react-native-brownfield. Use after the brownfield path has been selected, when setting up the integration, packaging XCFramework or AAR artifacts, or adding React Native surfaces to native hosts.

react-native-testing

Write tests using React Native Testing Library (RNTL) v13 and v14 (`@testing-library/react-native`). Use when writing, reviewing, or fixing React Native component tests. Covers: render, screen, queries (getBy/getAllBy/queryBy/findBy), Jest matchers, userEvent, fireEvent, waitFor, and async patterns. Supports v13 (React 18, sync render) and v14 (React 19+, async render). Triggers on: test files for React Native components, RNTL imports, mentions of "testing library", "write tests", "component tests", or "RNTL".

react-native-tv-best-practices

Reviews React Native TV apps for focus/D-pad navigation, 10-foot UI layout, TV playback/DRM integration, low-memory TV performance, and TV accessibility. Use when building, debugging, or reviewing react-native-tvos, Expo TV, Amazon Vega/Kepler, or React Native web TV targets where the issue depends on remote input, TV focus, TV packaging, TV hardware, or TV playback constraints.

react-navigation

Provides React Navigation UI patterns for stacks, tabs, drawers etc. Use when building navigation UIs with React Navigation, configuring headers, bottom sheets or handling safe areas and insets.

upgrading-react-native

Upgrades React Native apps to newer versions by applying rn-diff-purge template diffs, updating package.json dependencies, migrating native iOS and Android configuration, resolving CocoaPods and Gradle changes, and handling breaking API updates. Use when upgrading React Native, bumping RN version, updating from RN 0.x to 0.y, or migrating Expo SDK alongside a React Native upgrade.

validate-skills

Validates skills in this repo against agentskills.io spec and Claude Code best practices. Use via /validate-skills command.

vercel-react-native-skills

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

writing-user-docs

House style for user-facing documentation — voice, scope, structure, and what to leave out. Use this skill whenever writing, editing, or reviewing anything a user reads to learn how to use a tool — help center articles, getting-started guides, tutorials, feature docs, README usage sections, in-app help, release notes, or FAQ entries. Trigger it even when the request is phrased plainly — "document this feature", "write docs for X", "explain this to users", "write a README for this library", "turn these notes into a guide" — and even when no style guidelines are mentioned. Also use it to review existing docs for tone, bloat, or leaked implementation detail. Do not use it for internal engineering docs, architecture write-ups, RFCs, or code comments.

関連スキル