What you'll learn: By the end of this lesson you will be able to explain how React Native turns components into native views, describe the New Architecture (JSI, Fabric, TurboModules, Hermes) at the level an architect needs, split an app into a shared core, platform adapters and thin screens, express platform differences with platform files and
Platform.select, predict which file a bundler loads for each platform, and name the monorepo failures that appear when web and mobile share packages.
A restaurant chain shares its recipes across every branch, but each branch has its own oven. If the recipes assume one brand of oven, they fail in the branch that has another. Shared code in a mobile and web product works the same way: the recipes (rules, data, state) travel well; the ovens (storage, camera, haptics, the screen itself) differ, and the design question is where the boundary sits.
This lesson builds on mobile and cross-platform front ends and monorepos and shared libraries, and assumes React Native is already the right rung (the decision framework covers that). The running example is the grocery shopper app, shipping as a website, an iOS app and an Android app.
Verified on 2026-12-02 against the React Native, Metro, Expo, React Native for Web and TypeScript documentation. No phone, emulator or Xcode or Android build was available. The Node script on this page was run; every React Native snippet here is quoted from the docs or marked as not run.
The core idea
- React Native shares a programming model, not a rendering target. On a phone, components become the platform's own views, not DOM elements. Logic carries over to the web easily; UI does not, unless you add a compatibility layer.
- Share the rules, adapt the edges. Business logic, state transitions, validation and API clients are plain TypeScript in a package every app uses. Storage, camera, push and haptics sit behind small interfaces with one implementation per platform.
- A platform difference should be a file name, not an
ifscattered through the code. The bundler picks the file, so call sites stay identical.
How React Native renders
React Native's documentation says that "at runtime, React Native creates the corresponding Android and iOS views for those components", and that because they are backed by the same views as native apps they "look, feel, and perform like any other apps". The documented mapping for the core components:
| React Native | Android view | iOS view | Web analogue |
|---|---|---|---|
View |
ViewGroup |
UIView |
A non-scrolling div |
Text |
TextView |
UITextView |
p |
Image |
ImageView |
UIImageView |
img |
ScrollView |
ScrollView |
UIScrollView |
div |
TextInput |
EditText |
UITextField |
input |
The web column is an analogy for web developers; it does not mean React Native draws to the DOM. Two consequences matter for sharing code.
Styles are JavaScript objects. StyleSheet.create returns style objects, and a later style overrides an earlier one when you compose them. There are no CSS selectors, so a shared design system has to be written as components and tokens, not as a stylesheet. Layout is Flexbox, "the same way as it does in CSS on the web, with a few exceptions", and the defaults differ: flexDirection is column instead of row, alignContent is flex-start instead of stretch and flexShrink is 0 instead of 1. A layout copied from a web component can therefore stack where it should sit side by side.
There is no HTML: sharing screens means either writing them against React Native's components and mapping them on the web, or writing separate screens over a shared core.
React Native for Web takes the first route. Its documentation describes it as "a compatibility layer between React DOM and React Native": core components such as View, Text, Image, TextInput and ScrollView render with React DOM, and styles written in JavaScript "are converted to native CSS". Its stated goal is broad compatibility, so evaluate it against the screens you actually have.
Figure 1. Where a component goes on each target
How to read this: the left box is code you share. The two native targets are created by React Native itself; the web target needs an extra layer that maps the same components onto the DOM.
What the New Architecture changed
React Native's documentation says the New Architecture "removes the asynchronous bridge between JavaScript and native and replaces it with JavaScript Interface (JSI)", and that JSI "is an interface that allows JavaScript to hold a reference to a C++ object and vice-versa", so you can call methods "without serialization costs". Fabric is the new rendering system: it moves more render logic into C++ shared across platforms, can measure and render surfaces synchronously, and generates C++ structs from JavaScript component declarations, so that "mismatch between JavaScript and host component props triggers a build error". TurboModules are the native-module side, described below. The documentation states that "with 0.76, the New Architecture is enabled by default in all the React Native projects", after being experimental from 0.68, and gives opt-out switches for both platforms. Check library support before adopting it.
Hermes is the JavaScript engine: "used by default by React Native" and bundled per release. In release builds it compiles JavaScript to bytecode at build time. The documentation says startup, memory and size improve "for many apps", gives no figures and tells you to benchmark.
A native module, the typed way
When the web has no equivalent of a platform API, you write native code and expose it to JavaScript. The documented flow for a Turbo Native Module has four steps: write a typed specification in TypeScript or Flow; configure Codegen to generate native interfaces from it (it runs during an Android build and during pod install on iOS); call it from application code; and write the native implementation (Java or Kotlin on Android, Objective-C++ on iOS). The spec is the source of truth for both sides. It only works with the New Architecture.
Figure 2. One spec, two native implementations
How to read this: the top half happens at build time and the spec keeps both platforms honest; the last line is the only run-time step. This is the shape the documentation describes; the snippet itself was not run here.
Splitting the code: core, adapters, screens
A useful split has three layers, which the monorepo lesson's package-boundary rules enforce.
| Layer | Contains | Imports allowed | Shared with web |
|---|---|---|---|
| Core | Cart rules, money, validation, state reducers, API client types | Plain TypeScript only | Yes |
| Adapters | Storage, secure storage, camera, push, haptics: an interface in core, an implementation per platform | The platform's own APIs | Interface yes, implementation no |
| Screens | Navigation, layout, native components | react-native, the core, adapters |
Mostly no |
The test for the core is mechanical: it must not import react-native, window or document. If it does, it only happens to live in the shared folder. Layered and clean architecture for UI and module boundaries describe the same inward dependency direction.
Figure 3. Where does this code live?
plain TypeScript"] Q1 -->|"yes"| Q2{"Is it UI?"} Q2 -->|"no"| AD["Interface in core,
one implementation per platform"] Q2 -->|"yes"| Q3{"Same on every target?"} Q3 -->|"yes"| RNW["One component,
React Native for Web if sharing UI"] Q3 -->|"no"| SCR["Separate screens
over the shared core"]
How to read this: ask about the platform first, because that is what breaks sharing. Sharing UI is the last and most optional step.
Platform differences as file names
React Native offers two ways to branch. For a small difference, Platform.OS and Platform.select. The documentation says Platform.select takes an object whose keys can be ios, android, native or default, and returns "the most fitting value", preferring ios or android, then native, then default. For larger differences, the documentation says to split the code into files: React Native "will detect when a file has a .ios. or .android. extension and load the relevant platform file", so BigButton.ios.js and BigButton.android.js are imported as ./BigButton. A .native.js file is for a module shared by Node or the web and React Native with no iOS or Android difference: Container.js is picked up by a web bundler, Container.native.js by Metro for both phones. The documentation suggests having your web bundler ignore .native files.
Metro's resolution page gives the order. An exact path wins; otherwise, for each source extension in order, Metro tries the platform file, then the .native file (Metro sets preferNativePlatform), then the plain file. It also says that "extensions take priority over platforms: with the default sourceExts, Button.js wins over Button.ios.ts".
TypeScript does not know about platforms by default. Its moduleSuffixes option lets you set, for example, [".ios", ".native", ""] so an import of ./foo is checked against ./foo.ios.ts, then ./foo.native.ts, then ./foo.ts; the empty string is required. The documentation notes this suits React Native projects where each target platform can use its own tsconfig.json.
Illustration 1: the minimal example
The documented variant order is small enough to model. This script is this lesson's model of the Metro rule, not Metro: it prints the six variants from Metro's own example, then shows which file a shared package resolves to on each platform. Run in Node:
// A model of the variant order that the Metro resolution page documents.
function variants(base, platform, exts, preferNative = true) {
const out = [];
for (const ext of exts) {
out.push(`${base}.${platform}.${ext}`);
if (preferNative) out.push(`${base}.native.${ext}`);
out.push(`${base}.${ext}`);
}
return out;
}
console.log(variants("Button", "android", ["js", "jsx"]));
function resolve(files, base, platform, exts) {
if (files.includes(base)) return base; // an exact path wins first
return variants(base, platform, exts).find((f) => files.includes(f)) ?? null;
}
const shared = ["money.ts", "storage.ts", "storage.native.ts", "haptics.ts", "haptics.ios.ts"];
for (const platform of ["ios", "android"]) {
for (const base of ["money", "storage", "haptics"]) {
console.log(platform.padEnd(8), base.padEnd(8), "->", resolve(shared, base, platform, ["ts"]));
}
}
Output, from running it in Node 26.13.1:
[
'Button.android.js',
'Button.native.js',
'Button.js',
'Button.android.jsx',
'Button.native.jsx',
'Button.jsx'
]
ios money -> money.ts
ios storage -> storage.native.ts
ios haptics -> haptics.ios.ts
android money -> money.ts
android storage -> storage.native.ts
android haptics -> haptics.ts
The first six lines match the order in Metro's documentation. The last six show the three cases: money has no variants and is plain shared code; storage.native.ts serves both phones; and haptics has only an iOS file, so Android silently falls through to the plain haptics.ts. That fallthrough is the point of the next section.
Illustration 2: the realistic example
The shopper app has a cart, promotions, checkout and order tracking. Shared core: money arithmetic and rounding, promotion eligibility, the cart reducer, validation and the typed API client. These are the pieces whose bugs cost money, and they run under plain Node tests with no device. Adapters: a Storage interface (browser storage on the web, the platform's secure store on phones), a Scanner (camera on phones, none on the web) and Haptics. Screens: separate navigation and layout per target, over the core. A few presentational components might be shared through React Native for Web after testing in a browser; checkout is written twice because keyboards and layout differ.
Illustration 3: a failure, a missing platform file
In the script, haptics.ios.ts exists and haptics.ts is a stub added so TypeScript compiles. On Android the stub runs, and the app silently does nothing where iOS gives feedback. Nothing fails at build time. Two defences: make the plain file an honest default (a documented no-op or a thrown "not supported" error) and add an Android file when the feature matters; and keep a test per platform that asserts which file each shared module resolves to, as the script does.
A costlier failure lives in the monorepo. Expo's monorepo guide says duplicate React versions in one app "will cause runtime errors" and duplicate React Native versions in one monorepo "are not supported", and that native modules must never be duplicated because a build can compile only one version of each. It notes that some React Native libraries may fail to build or resolve under isolated installs (the pnpm default), with nodeLinker: hoisted as the documented fallback. When a shared package and the app disagree on a version, the error shows up at run time on a device.
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Share only the core | Rules in one place; fast Node tests | Screens written twice |
| Share UI through React Native for Web | Fewer screens to write | A compatibility layer to evaluate and a web bundle shaped by it |
| Platform files | No scattered if |
Silent fallthrough |
| Native modules (TurboModules) | Reach any platform API | Native code in two languages to maintain |
| One monorepo for web and mobile | Atomic changes, shared versions | Version pinning, Metro and native linking care |
Build it
This lesson has no lab. React Native code needs a device or simulator and native toolchains, none of which were available. The Node script above models only the documented file-resolution order. Everything else is quoted from the documentation and was not run; no number about speed or bundle size is claimed.
In practice: the shopper app on three targets
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
A marketplace with a React website adds a React Native app. The mobile team copies the cart and promotion code into the app. Later a rounding fix lands on the web and not in the app, and customers see different totals.
Starting architecture
Figure 4. Two copies of the rules
How to read this: the two warning boxes each hold their own copy of the cart logic, so every rule change is two changes and the copies drift.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Shared core package in a monorepo | One set of rules, Node-tested | Workspace setup, version alignment | Mobile version mismatch at run time |
| Share all UI through React Native for Web | Fewer screens | Rewrite of the web UI | Compatibility surprises |
The decision
| Field | Decision record |
|---|---|
| Context | Cart and promotion rules are duplicated and have diverged. |
| Decision | Extract cart, money, promotions, validation and the API client into a plain-TypeScript core package in a workspace. Put storage, scanner and haptics behind interfaces. Keep screens per platform. |
| Consequences, good | One rounding fix; core tests run in Node; adapters are replaceable. |
| Consequences, bad | A workspace to maintain; a boundary rule to enforce by a check. |
| Revisit when | Many presentational components are identical, which would justify evaluating React Native for Web. |
Rollout and verification
- Extract the core with its tests first, without changing either app.
- Switch the web app to it, then the mobile app, one rule set at a time.
- Add a boundary check that fails if core imports a platform package.
- Pin one React and one React Native version and test a device build before merging.
The 2 a.m. failure
After a dependency bump, the mobile app crashes at launch while the web app is fine. The workspace now resolves two copies of React through a shared package.
First three checks: (1) list the installed versions of react and react-native in the workspace; (2) check whether the shared package declares them as dependencies instead of peer dependencies; (3) compare the failing build against the last good lockfile. Mitigation: roll back the bump and pin one version with an override or resolution. Follow-up: a CI step that fails when the workspace contains two versions of either package.
Architect's notes
- Draw the core's import boundary and enforce it. A rule that is not checked erodes.
- Share logic before UI. Rules are where duplicated bugs cost money.
- Treat native modules as a cost centre. Prefer a maintained library when one exists.
- Make fallthrough visible. A plain file that stubs a platform feature should say so.
Common mistakes
- Importing
react-nativeorwindowinside the shared core. - Copying web styles and expecting the same layout despite the different flex defaults.
- Leaving a stub as the default for a platform that needs the feature.
- Two versions of React or React Native in one workspace.
- Assuming React Native for Web covers every component without testing the screens you have.
Key takeaways
- React Native creates the platform's native views from React components; it is not a browser.
- The New Architecture replaces the asynchronous bridge with JSI, adds Fabric and TurboModules, and is on by default from 0.76.
- Share the rules, put platform APIs behind interfaces, write screens per platform unless React Native for Web fits.
- Metro tries the platform file, then
.native, then the plain file; extensions beat platforms. - A shared package fails at run time when versions of React, React Native or a native module are duplicated.
Practice exercises
Exercise 1: Starter (30 min). Add storage.android.ts to the file list in Illustration 1 and predict, then check, what each platform resolves for storage.
Exercise 2: Intermediate (2 hours). Write a small Node script that scans a core package's source files for imports of react-native, window or document and reports each; run it on a package you own.
Exercise 3: Advanced (half day). Read the Turbo Native Module guide and write the typed spec for a Scanner for the shopper app. State what you could not run.
Related reading
In this course:
- Mobile and Cross-Platform Front Ends: the five approaches compared.
- Responsive Web, PWA or Native: a Decision Framework: whether to climb to a native rung at all.
- Monorepos and Shared Libraries: workspaces, the package graph and boundaries.
- Layered and Clean Architecture for UI: the inward dependency rule.
Official documentation
- React Native: Platform-specific code:
Platform.selectand platform file extensions. - React Native: The New Architecture and Fabric: JSI, concurrent rendering and the default version.
- React Native: Turbo Native Modules: the spec, Codegen and native implementation.
- React Native: Hermes and Core components: the engine and the native view mapping.
- Metro: Module resolution: the order of platform and extension variants.
- Expo: Work with monorepos: Metro, duplicate versions and autolinking.
- React Native for Web: the compatibility layer.
- TypeScript: moduleSuffixes: checking platform files.