All skills
callstackincubator avatar

/react-native-best-practices

@fa0bad0 official

Provides React Native performance optimization guidelines for FPS, TTI, bundle size, memory leaks, re-renders, and animations. Applies to tasks involving Hermes optimization, JS thread blocking, bridge overhead, FlashList, native modules, or debugging jank and frame drops.

Use this Skill: https://skilld.dev/gh/callstackincubator/agent-skills/react-native-best-practices

This session only. Nothing lands on disk.

referencesjs-profile-react.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Skill: Profile React Performance

Identify unnecessary re-renders and performance bottlenecks in React Native apps using React Native DevTools through agent-device react-devtools.

Quick Command

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

Drive the target interaction with normal agent-device commands between profile start and profile stop. For targeted audits, profile the exact flow under review. Baseline output should include commit timeline, re-render counts, slow components, and a breakdown of the heaviest commit.

When to Use

  • App feels sluggish or janky during interactions
  • Need to identify which components re-render unnecessarily
  • Investigating slow list scrolling or form inputs
  • Before applying memoization or state management changes

Prerequisites

  • React Native DevTools connection available through agent-device react-devtools
  • App running in development mode
  • React DevTools version compatible with the app's React and React Native versions
  • For release-build profiling, @callstack/inspector installed and connected first

Note: Prefer agent-device react-devtools over the visual DevTools UI for token-efficient React profiling and debugging. Use the visual UI or exported profiler JSON only when the CLI output is insufficient. Record concrete commit times, render counts, and component names.

Manual fallback when agent-device is unavailable: open React Native DevTools from Metro (j) or the Dev Menu, use the Profiler tab, and record the same interaction. Keep this as fallback only; agent runs should prefer the CLI summaries above.

Step-by-Step Instructions

1. Connect React Native DevTools

agent-device react-devtools status
agent-device react-devtools wait --connected

If status reports the helper is not running, start it first:

agent-device react-devtools start
agent-device react-devtools wait --connected
Release Builds

React Native release builds do not expose the same profiling path by default. Before using agent-device react-devtools against a release app, wire in @callstack/inspector:

npm install @callstack/inspector
npx inspector start

Import @callstack/inspector as the first module in the app entrypoint, wrap Metro config with withInspector(config, true), then build and run the app in release mode. For Expo, use a release build from prebuild/dev-client flow; Expo Go is not a release-build profiling target.

2. Record a Profiling Session

agent-device react-devtools profile start
agent-device react-devtools profile stop

Drive the exact interaction or navigation flow under review between those two commands.

For AI-agent workflows, treat this as a required sequence:

  1. Run agent-device react-devtools status.
  2. Run agent-device react-devtools wait --connected.
  3. Start profiling immediately before the audited interaction.
  4. Drive the flow with normal agent-device commands.
  5. Stop profiling.
  6. Inspect slow components, re-render counts, and commit timing before proposing fixes.

3. Analyze Results

React DevTools Flamegraph

Use bounded CLI summaries first:

agent-device react-devtools profile slow --limit 5
agent-device react-devtools profile rerenders --limit 5
agent-device react-devtools profile timeline --limit 20

Then drill into a specific component:

agent-device react-devtools profile report @c5
agent-device react-devtools get component @c5

Use the component ref printed by profile slow, profile rerenders, or get tree; @c5 is only an example.

Use the visual flame graph or exported profiler JSON only when the bounded CLI summaries do not answer the question.

4. Profile JavaScript CPU

For non-React CPU issues, use platform CPU profilers or agent-device perf instead of React DevTools render profiling.

Interpreting Results

Symptom Likely Cause Solution
Many yellow components Cascading re-renders Add memoization or use React Compiler
"Props changed" on callbacks Inline functions recreated Use useCallback
"Parent component rendered" State too high in tree Move state down or use atomic state
Long JS thread block Heavy computation Move to background or use useDeferredValue

Only propose callback or dependency-array changes when the profiler or a reproducible bug shows they matter. Do not infer stale closures from a snippet alone.

Common Pitfalls

  • Using one build type for every question: Use agent-device react-devtools in development to identify render causes, commit patterns, and expensive components. Validate timing-sensitive FPS/CPU improvements in production or release-like builds.
  • Not using production builds: Some issues only appear with minified code
  • Ignoring "Why did this render?": This tells you exactly what to fix
  • Using component tree depth or count as the main baseline: These are secondary context, not the core performance signal

Related Skills

Source: SKILL.md on GitHub

1 alert17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides a comprehensive performance optimization guide for React Native applications. It contains standard developer workflows using command-line tools and patterns for advanced techniques like remote code splitting, which include detailed security hardening advice.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    11/31 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at fa0bad0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago
  • Performance
  • react-native
  • optimization
  • profiling
  • fps
  • bundle-size
  • memory
  • hermes
  • flatlist
  • animations

README badge

README badge for callstackincubator/agent-skills/react-native-best-practices

Provides React Native performance optimization guidelines covering FPS, TTI, bundle size, memory leaks, re-renders, and animations. Includes reference documentation for Hermes, FlashList, Turbo Modules, React Compiler, Reanimated, and profiling with Xcode and Android Studio.

Generated from the current SKILL.md.

Does this skill cover Expo apps?
Yes. The guidelines apply to both bare React Native and Expo projects. Expo SDK 52+ supports tree shaking and Re.Pack code splitting.
What performance metrics should I measure first?
Start with FPS (use React Native DevTools), Time To Interactive (TTI), bundle size, and memory growth. The skill emphasizes measuring baseline metrics before and after optimization to validate improvements.
Does this cover Hermes optimization?
Yes. The skill includes Hermes-specific guidance such as disabling JS bundle compression on Android to enable mmap, and checking Hermes API coverage before removing polyfills.
What if I'm using a list library other than FlatList or FlashList?
The skill prioritizes FlatList and FlashList as virtualized replacements for ScrollView. It includes library version checks (e.g., FlashList v2 API changes) but focuses on these two libraries.
Does this include native profiling guidance?
Yes. The skill covers profiling with Xcode Instruments (iOS) and Android Studio CPU Profiler, plus guidance on native threading, Turbo Modules, and C++ performance-critical code.

Generated from the current SKILL.md. These answers refresh after source changes.