Native code · mid
When to write native code, and which way
Write native code when you need a platform API, a native SDK or CPU-heavy work that no maintained library covers; choose a native module for an API and a native component for a view; and pick a Turbo Native Module, the Expo Modules API or Nitro based on language, call speed and maintenance.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Native module = functions and events (SDK wrapper, biometrics, device info). Native component = a view inside your tree (map, camera preview, video player, chart).
- First search reactnative.directory and the Expo SDK; a maintained library beats your own native code that you must update every RN release.
- Turbo Native Module: core React Native, spec + Codegen, Objective-C++/Kotlin/C++. Best when you need shared C++.
- Expo Modules API: a Swift/Kotlin DSL (Name, Function, AsyncFunction, Events, View, Prop) built on JSI. Works in bare apps too (adds the expo package). SDK 56 allows inline modules inside the app; SDK 58 ships Expo Modules 2.0 beta.
- Nitro Modules (Margelo): typed HybridObjects with the nitrogen code generator and direct Swift↔C++ calls. MMKV v4 and VisionCamera v5 use it. Nitro's own benchmark (100k tiny calls): Nitro 7 ms, Turbo 116 ms, Expo Modules 435 ms; this only matters for very hot calls.
- Threading: a sync function blocks the JS thread; do I/O in async functions. A main-thread-only SDK must dispatch to main and resolve its promise exactly once.
- Lifecycle: clean up listeners in invalidate / OnDestroy, handle a JS reload (Fast Refresh, OTA reload) while a callback is pending, and null-check the current Activity on Android.
The red pen
Common traps: mistake → fix
Mistake: "Go native for performance" without a profile
Fix: most slowness is React or JS work; measure first.
Mistake: "Expo Modules only work in Expo Go"
Fix: they work in any app with the expo package and a development build.
Mistake: "Resolve the promise in every SDK callback"
Fix: resolving twice is a bug; settle once.
Easy to hard
Questions interviewers ask, easy to hard
- What is a native module vs a native UI component?
- Tell me about a real case where no library existed. What did you do?
- Turbo Module, Expo Module or Nitro: which would you choose and why?
- A native SDK must run on the main thread and takes a callback. How do you expose it safely to JS?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.