react-brain
Menu · Topics

Sharing code across React (web) & React Native

our pick

Shared logic/hooks package (a platform-agnostic workspace package used by both the React web app and the React Native app) first — the highest-leverage, lowest-risk win. For shared UI on NEW projects the pick is Expo Universal Components in an Expo app, otherwise react-native-web (maintained again since 2026-10 under Expo + the React Foundation) for RN-primitive authoring; React Strict DOM stays an option for strict HTML/CSS authoring but has shipped nothing to npm since 2026-01. The pick changes only for an organisation that can staff and gate agent-maintained duplicate native implementations (see when).

unless your situation is different

  • duplicated business logic across web + native : use shared logic/hooks package (extract a workspace package now)
  • UI that must differ per platform behind one API : use platform-extension files (.web.tsx/.native.tsx)
  • new universal UI in an Expo app : use Expo Universal Components (@expo/ui; native lanes stable, web lane experimental)
  • new universal UI authored with RN primitives, web as a real target : use react-native-web (maintained again since 2026-10; expect the breaking 0.22: React 19-only, ESM, newer browsers)
  • new universal UI authored as strict HTML/CSS, web-first : use React Strict DOM (pre-1.0, involved setup, no npm release since 2026-01-09 — pin and watch)
  • existing react-native-web app : use react-native-web (keep it; maintained again — move to React 19 before the 0.22 line)
  • react-native-web app whose web UI no longer shares code with a native app : use a plain web component stack (X's route; see note: X)
  • existing Tamagui design system : use Tamagui (keep it; cross-platform UI with an optimizing compiler)
  • Expo + Next.js shared routing : use Solito
  • incremental web reuse inside an RN app : use Expo DOM Components (`use dom`)
  • native-only mobile org that can staff and gate agent-maintained duplicate Swift/Kotlin implementations : use share the spec, not the code (Shopify's route; see note: SHOPIFY)

Save this choice as a decision record → · Check my app against it

How sure are we?
confidence
high — well-evidenced and stable — safe to default to
track record at this confidence
83% held up, 6 of 11 graded
depth
reviewed — checked against primary sources, with a long-form explanation
evidence
14 sources · 6 readings
last checked
on build day · re-checked 6×

how we check →

#Options compared

what else we looked at, and the tradeoff of each · compare side by side →

optiontradeoff
shared logic/hooks package · our pickplatform-agnostic core (business logic, state, data) in a workspace package; serves the web app and the native app alike — the highest-leverage, lowest-risk share
platform-extension files (.web.tsx/.native.tsx)one API, per-platform implementation; keeps each file single-platform instead of Platform.OS branching
React Strict DOM (Meta)write strict HTML/CSS rendering web + native; Babel flattens to real DOM + static CSS on web; involved setup. Pre-1.0 and QUIET: 0.0.55 (2026-01-09) is still the latest npm release and the repo's last commit is 2026-08-31 (both verified 2026-10-15); see note: REACT-NATIVE-WEB
react-native-webMAINTAINED AGAIN since 2026-10-07 — maps RN primitives to HTML; Expo-backed maintainers took it over with its creator and it is moving to the React Foundation org. A breaking 0.22 modernization is planned (React 19-only, ESM, newer browser floor). 0.21.4 (2026-10-08, verified vs npm); see note: REACT-NATIVE-WEB
Tamaguicross-platform UI + optimizing compiler; 3.0 (2026-10-10, verified vs the v3.0.0 release) adds React Strict DOM elements and a Tailwind authoring mode on the same compiler and is a breaking major for v2 apps — RB-E-STYLING owns the detail (see note: TAMAGUI 3 there)
Expo Universal Components / @expo/uisingle API → SwiftUI (iOS) / Jetpack Compose (Android) / react-dom or react-native-web (web); native APIs stable since SDK 56, web APIs still experimental (verified vs the SDK 56 changelog); see note: EXPO UI
Solitoshared routing across Expo + Next.js; v5 dropped the RN-Web core dep
Expo DOM Components (`use dom`)render real web components inside RN via a webview wrapper (since Expo SDK 52); good for incremental web reuse

#Key facts

Share by layer. Logic, state and data are platform-agnostic, so a shared workspace package is the highest-leverage, lowest-risk win — and in a React web + React Native codebase it also serves the web app. When logic or components are duplicated across a web app and a native app, that duplication is the prime target. UI that diverges per platform is split by platform-extension files so each file stays single-platform; widespread inline Platform.OS branching means sharing happens at the wrong layer. Universal UI is picked only on a maintained lane.

REACT-NATIVE-WEB (2026-10-15, verified vs necolas/react-native-web discussion #2872 and npm)
earlier in 2026 react-native-web sat in MAINTENANCE-ONLY mode — creator Nicolas Gallagher and Zalando had pivoted to React Strict DOM. That reversed on 2026-10-07: Mathieu (@zoontek), with Gallagher, Expo and the community, picked up active maintenance and development, and the repo is moving to the React Foundation GitHub org next to React and React Native. Gallagher called it "the ideal outcome for RNW". The direction is conservative — track React Native as closely as practical; native/web convergence questions belong to React Native and React Strict DOM. Releases resumed (0.21.3 2026-09-25, 0.21.4 2026-10-08). The modernization lands on a 0.22-dev branch and is BREAKING: react/react-dom peers ^19.0.0 (React 18 dropped), browser floor Chrome/Edge 95+, Firefox 93+, Safari/iOS Safari 15.1+, an ESM ("type": "module") package, Flow → TypeScript, removal of modules React Native core no longer has (CheckBox, Picker, ProgressBar, YellowBox, InteractionManager, the old Touchable mixin), missing RN APIs added (PlatformColor, useAnimatedValue, usePressability and more), and babel-plugin-react-native-web deprecated in favour of a bundler alias plus tree shaking. Meanwhile React Strict DOM has gone quiet: 0.0.55 (2026-01-09) is still its latest npm release and the repo's last commit is 2026-08-31; in the same thread contributors described its activity as "mostly stalled since spring", and Gallagher suggested Expo might help there "at some point". → react-native-web is a maintained lane again and no longer a bet to avoid; React Strict DOM is still an option but pin it and watch for a release. Existing RN-Web apps should get onto React 19 before 0.22.

EXPO UI (2026-09-24, verified vs the SDK 56 changelog)
SDK 56 made the Expo UI native APIs stable and added universal components across Android, iOS and web, backed by @expo/ui/jetpack-compose, @expo/ui/swift-ui and react-dom or react-native-web; the web APIs are still experimental and likely to change.

Expo apps get a universal-UI lane without splitting files; treat its web half as unstable.

SHOPIFY (2026-09-21, verified vs shopify.engineering/back-to-native)
Shopify is moving its mobile apps off React Native to Swift and Kotlin. It adopted RN in 2020 to stop building features twice, let developers work across the stack and stop chasing parity; all three delivered. Its reason to leave: coding models made "building the same feature in Swift and Kotlin" no longer carry "the cost it used to", so sharing an implementation lost value while platform closeness and first-party tooling did not. It does not claim RN is slow ("React Native apps can be fast. Ours are") or was wrong ("React Native was the right choice for Shopify in 2020"). Its replacement is the new option in this design space: duplicate the implementation per platform and hold parity through shared specifications, tests and review checkpoints that agents execute, with an agent implementing a feature on Android using the iOS version as a reference — "share the spec, not the code". The default still holds on this entry's terms: (1) the default's claim is about LOGIC, and two agent-maintained copies are cheaper than before but not free ("that cost has not disappeared"); (2) the migration is not a swap a normal team can copy — greenfield rebuilds, a bespoke checkpoint-gated system (Helix), and business logic re-architected to run headless for agents; (3) this entry's scope includes the web app, which a shared logic package also serves and which Shopify's decision does not weigh.

A team with that machinery has a real alternative to sharing code; a team without it still pays full price for duplicated logic. The revisit trigger is a second organisation of that size publishing the same conclusion.

COINBASE (2026-10-15, verified vs a 2026-09-30 LinkedIn post by the Coinbase engineer whose team runs the migration — a hiring post, not an engineering write-up)
Coinbase is taking its consumer trading app fully native, off React Native to Swift and Kotlin, with the same core reason as Shopify — "AI coding agents have collapsed the cost of building a feature twice" — plus claimed faster startup, fewer crashes and day-one access to new platform capabilities. That meets the revisit trigger above in weak form. Re-checked, the default holds on the same three terms: the default is about LOGIC; this is a staffed native rewrite (the post is hiring native-mobile and mobile-QA engineers, Senior to Senior Staff), not a swap a normal team copies; and no web app is weighed.

Two consumer-scale apps now make agent-maintained duplication a trend rather than one outlier; the next revisit trigger is a published technical account (costs, parity machinery) from Coinbase or a third organisation.

SHOPIFY REBUILD (2026-11-25, verified vs shopify.engineering/shopify-app-rebuild, 2026-11-10)
the revisit trigger above fired — Shopify published the technical account. ~30 engineers in pods of two rebuilt the 300+-screen app from React Native to Swift and Kotlin in 12 weeks, agents writing most of the code. Spec-driven development failed (specs went stale within a screen's checkpoints); the legacy RN app WAS the spec, checked checkpoint by checkpoint by Helix. Consistency beat platform idiom — the same ViewModel shape on both platforms, one PR per feature for both, CI failing on iOS/Android divergence. That is parity machinery a normal team does not have, so the default's second term holds harder, not softer: the cheap part was the code, the expensive part was the system around it.

DISCORD (2026-11-05, verified vs The Verge, which quotes CTO Stanislav Vishnevskiy's X post)
Discord is moving its whole client to Rust — "Electron goes away, and so does React Native, mobile keeps native UI but shares app code with desktop via Rust" — with no ship date ("testing with users soon"). This is the third consumer-scale exit after Shopify and Coinbase, but the reason differs: not agent-maintained duplicate UIs, but a SHARED NATIVE CORE (Rust) under per-platform UI — the KMP/shared-logic shape, in another language. It is evidence FOR this entry's default (share logic, pick the UI per platform) and against only the JS runtime as the logic carrier.

Agent-maintained duplication (Shopify, Coinbase) and native UI over a shared core (Discord) are now the two documented exits; both keep logic single-sourced or pay for elaborate parity gates, and each came from a company with the staff to run native UI teams. Next revisit: a mid-size team (not a 30-engineer pod system) publishing the same migration. GOBI (2026-11-17, Software Mansion) is the incremental version of the exit — see reading.

X (2026-11-04, content verified via Wayback snapshot 2026-11-15 — blog.x.com answers 403 to scripted fetches): x.com — the app React Native for Web was built for — replaced its rweb client (Redux + Relay, styled through React Native for Web, Flow) with Vite + React streaming SSR + Fastify + Relay and a new component library (XDS) on Base UI + Tailwind CSS; slow-connection first post moved from 23.9 s to 2.7 s on a slow-connection lab recording. RNW's flagship user left the "one RN codebase on the web" model once its web UI stopped being shared with mobile → read alongside RNW's new maintainers (above), not as its end: RN-Web stays the choice when UI is actually shared with an RN codebase, not the default for a web-only app. RB-E-META-FRAMEWORKS owns the SSR-without-a-framework half.

TV / VEGA (2026-10, verified vs Amazon's launch post + the Vega 2.0 release notes)
Vega OS 2.0 — the React Native-based OS on newer Fire TV and Echo devices — is GA and rolled out to all Vega Fire TV devices. SDK 2.0 moves apps from RN 0.72 to RN 0.83 (React 19, React Compiler, Hermes v1, RN DevTools; already New Architecture), keeps its API stable across minors with breaking changes once a year, and in the 0.83 library set stops resolving deep imports and replaces @amazon-devices/react-linear-gradient with the experimental_backgroundImage style prop.

An RN TV app targeting Fire TV is a supported first-party target, a few releases behind core RN.

CROSS-REFERENCES
RB-E-AI-DEVTOOLS owns the agent-workflow half of the Shopify thread (Helix, headless agent-drivable business logic). The engineering-principles skill owns boundaries and dependency direction for the shared package.

What changed on this page (5)
  1. reopened Shopify technical account (12-week rebuild) + Discord (Rust core, native UI; drops RN and Electron) + X drops RN-Web on x.com + Gobi incremental exit (reading) + Vega OS 2.0 GA (RN 0.83 on Fire TV); default holds — two documented exit shapes, both keep logic single-sourced.
  2. reopened react-native-web is maintained again (Expo-backed maintainers + React Foundation org, 2026-10-07) — option row, default, when-clauses and note rewritten; React Strict DOM flagged quiet (no npm release since 2026-01-09). Coinbase datapoint added to the Shopify thread.
  3. reopened Tamagui row notes 3.0 (React Strict DOM + Tailwind mode; breaking for v2), pointer to RB-E-STYLING.
  4. corrected the Expo UI row said "SDK 56 beta"; SDK 56 made the native APIs stable and left only the web APIs experimental.
  5. challenged → survives Shopify's move off RN attacked the share-an-implementation premise with "share the spec, not the code" (agent-maintained duplicates); default holds, competitor named as a when-clause.

This page helps you choose; the engineering-principles skill covers how to use it well.

#Read more

why each piece is worth your time — the links go to the originals

How Does KMP with SwiftUI Scale on iOS?Andrei Calazans

The best-measured statement of the ALTERNATIVE this entry's axis implies — share the logic layer, keep the UI native — taken to production scale on Kotlin Multiplatform: ~750 Kotlin and ~700 Swift files, all figures measured wall-clock on an M4 Pro with Xcode 26.5 / Kotlin 2.4.0 / Gradle 9.6.1 rather than estimated. Two structural facts are the transferable part. (1) iOS consumes the shared layer as ONE linked framework no matter how many Gradle modules it is split into, because every linked KMP framework embeds its own copy of the Kotlin/Native runtime, memory manager and GC — ship two and you get two uncoordinated collectors in one process, with Kotlin objects crossing a boundary neither manages, so the single umbrella framework is the SAFE shape and its link step is the price of that safety, not a tooling accident. 'Just split the framework' is therefore not a free lever. (2) The decision he rates highest is that Swift feature packages compile against Swift CONTRACTS (closure-struct protocols), not against the Kotlin framework — only a thin SharedBridge imports it — which is the same insulation principle this entry applies to platform-extension files. Useful whether or not you would pick KMP: it prices the seam that any share-the-logic architecture has to own.

use dom — incrementally migrating web UI to native with ReactEvan Bacon (Expo)

Deep-dive on Expo DOM Components and the `use dom` directive — run real web UI inside a native app and migrate to native views component-by-component; covers the Metro bundling, offline support, and honest WebView trade-offs. The primary source for the incremental-reuse path.

AI-Assisted React Native Migration for TV: Lessons From ZattooCallstack (Zattoo case study)

TV/cross-platform RN case study: share until a platform gives a reason to split, telemetry-driven perf, team reorg, and a deflated, realistic account of AI's role. A concrete companion to this entry's share-by-layer thesis.

How we rebuilt the Shopify app in 12 weeksShopify Engineering (Remi Vanhee)

The cost-and-machinery account behind the SHOPIFY REBUILD note: ~30 engineers in pairs, 12 weeks, 300+ screens moved from React Native to Swift/Kotlin with agents writing most of the code. The transferable findings are about the system around the agents: written specs went stale and the live legacy app became the spec; consistency across platforms was enforced by CI rather than idiom; the bottleneck moved from writing code to review, validation and emulator capacity.

Migrating from React Native to Swift and Kotlin, One Feature at a Time – the Gobi StorySoftware Mansion (VENDOR — the agency that did the migration)

The incremental-exit playbook the Shopify thread lacks: start by moving the hot paths native (sheets, then map markers — 120 FPS came from moving camera-driven marker generation out of JS), introduce native hosts, keep unmigrated features running as React Native 'islands' (separate AppRegistry roots in one lazily-started JS runtime — reverse brownfield), fix a navigation contract both platforms implement, and drop the OTA path because new client code now needs a build. ~11 weeks for the main transition; agents did small reviewed tasks, checking visual parity with screenshot diffs.

Rebuilding the global town square from scratchX Engineering (Yagiz Nizipli)

X's web app moved off React Native for Web, Redux, styled components and Flow onto Vite, React, Fastify, Relay and a Base UI + Tailwind component library, with streaming SSR and one server for people, crawlers and link previews; slow-connection first post went from 23.9 s to 2.7 s. A large-scale datapoint that RN-Web stops paying for itself once web UI is no longer shared with mobile. (Live URL 403s to scripted fetches; content verified via Wayback snapshot 2026-11-15.)

#The full story

Read why · ≈6 min

the long-form reasoning behind this pick — the why, not a how-to · also on GitHub

About sharing code across React (web) & React Native

Diataxis: Explanation. This is the conceptual core of why react-brain exists: when a team maintains both a web app and a native app, duplicated logic is the prime target. This page explains how to think about sharing and why the recommendation is shaped the way it is. The option list lives in the index entry RB-E-CROSSPLATFORM.

"Write once, run anywhere" is the wrong frame

The seductive promise is one codebase for web and native. The durable reality is subtler: some layers share almost for free, and one layer — UI — fights you. Teams that try to share everything hit an abstraction tax (leaky Platform.select everywhere, lowest- common-denominator components) and conclude "cross-platform doesn't work." Teams that share by layer get most of the benefit with little of the pain. So the real question is not "share or not" but "which layers, and how far up the stack?"

The layered model (the mental model to keep)

Think of an app as a stack, sharing-friendliness decreasing as you go up:

  1. Logic & hooks — pure functions, business rules, validation, formatting, custom hooks. Platform-agnostic by nature. Share first; this is the highest-leverage, lowest- risk win.
  2. State & data — client state (RB-E-STATE) and the data layer (RB-E-DATA). The leading libraries (Zustand, TanStack Query) are already platform-agnostic, so this layer shares cleanly — put it in the common package.
  3. UI — components and styling. This is where platforms genuinely differ (navigation patterns, gestures, native controls, motion), and where "share everything" goes wrong. Share here only with eyes open, using one of the dedicated approaches below.

The single most useful action for most teams is unglamorous: extract a platform-agnostic logic/hooks package (layers 1–2) into the monorepo and consume it from both apps. That alone removes most duplication and the bugs that come from two drifting copies — and it's reversible and low-risk. Depth on package boundaries and dependency direction is owned by engineering-principles.

The default, and why

Shared logic/hooks package (a platform-agnostic workspace package used by both the React web app and the React Native app) first — the highest-leverage, lowest-risk win. For shared UI on new projects the pick is Expo Universal Components or React Strict DOM, not a fresh react-native-web bet. The pick changes only for an organisation that can staff and gate agent-maintained duplicate native implementations.

The UI clause carries a verified, load-bearing 2026 shift (below). The ordering — logic before UI — is deliberate: it front-loads the cheap, certain wins and defers the hard, opinion-heavy UI decision until you actually need shared components.

The verified shift you must not miss

react-native-web has entered maintenance-only mode. Its creator, Nicolas Gallagher, and early adopter Zalando have pivoted to React Strict DOM (RSD), and Software Mansion's ecosystem read is "no major features on the horizon." This does not mean existing RN-Web apps are in trouble — they keep working. It means a new universal bet should not be placed on RN-Web's continued evolution. This is why the default points elsewhere for greenfield UI sharing. (Sources: Gallagher's "One React for web and native"; Callstack's "From React Native Web to React Strict DOM.")

The deeper reason RSD is the heir: RN-Web works by mapping React Native primitives onto HTML (native-first, web-as-target), whereas RSD inverts it — you write strict HTML and CSS, a Babel step flattens it to real DOM + static CSS on web and to RN styles on native (web-standards-first). That direction aligns with where the platform is going.

The UI-sharing landscape, and when each wins

Platform-extension files (.web.tsx / .native.tsx) — one import, two implementations resolved by the bundler. Simple, explicit, no framework buy-in; the honest default when a handful of components need to diverge. It scales poorly if most components need it (then you wanted a real cross-platform UI layer).

React Strict DOM (Meta) — the strategic bet for new universal UI: write standards-based HTML/CSS once, render web + native. Cost is an involved, multi-step setup and a younger ecosystem — you're betting on the trajectory, not the maturity.

Expo Universal Components / @expo/ui — a single component API that renders as native SwiftUI (iOS) / Jetpack Compose (Android) / react-dom (web). Wins on platform fidelity (real native controls, not bridged approximations) and pairs naturally with an Expo app, which is why the entry picks it first for new universal UI inside Expo. Since SDK 56 the native APIs are stable; the web half (backed by react-dom or react-native-web) is still experimental and likely to change. The tradeoff is Expo coupling and an unstable web lane.

Tamagui — cross-platform UI kit with an optimizing compiler; a more batteries-included route when you want a component system rather than primitives.

Solito — not a UI layer but a shared-routing bridge across Expo Router + Next.js, so navigation is one mental model across web and native (see RB-E-NAV).

Expo DOM Components (use dom) — render real web components inside a React Native app via a webview wrapper. The pragmatic escape hatch for incremental reuse of existing web UI in a native shell, not a foundation for a whole app.

The strongest counter-argument: share the spec, not the code

In September 2026 Shopify announced it is moving its mobile apps off React Native to Swift and Kotlin. It does not say RN was slow or wrong — "React Native was the right choice for Shopify in 2020." Its reason is that coding agents made building the same feature twice cheap enough that sharing an implementation lost its value; parity is now held by shared specifications, tests and review checkpoints that agents execute. The entry records this as a named competitor, not a reversal: two agent-maintained copies are cheaper but not free ("that cost has not disappeared"), Shopify's route needed greenfield rebuilds and a bespoke checkpoint-gated system (Helix), and its decision weighs no web app — the case where a shared logic package pays twice. An organisation with that machinery has a real alternative; one without it still pays full price for duplicated logic. The agent-workflow half of the thread lives in RB-E-AI-DEVTOOLS.

Tradeoffs and failure modes to name out loud

  • Sharing UI too aggressively — chasing a single component tree across platforms produces lowest-common-denominator UX. Platforms have conventions (back gestures, tab bars, native pickers); the ecosystem trend is to honor them, not paper over them.
  • The abstraction tax — every Platform.select and per-platform branch is coupling. If a "shared" component is mostly branches, it isn't shared; split it.
  • Rendering RN-on-web vs building web properly — RN-Web-style approaches can yield un-idiomatic, heavier web output. RSD's standards-first direction exists precisely to avoid this.
  • Framework lock-in — Expo Universal Components and Solito tie you to Expo/Next; fine if you're already there, a cost if you're not.

How it interacts with the rest of the stack

  • State & data (RB-E-STATE, RB-E-DATA) — these share cleanly and should live in the common package; they're the easy 80%.
  • Styling (RB-E-STYLING) — RSD is both a code-sharing and a styling strategy (it compiles to static CSS on web); the two entries describe the same tool from two angles.
  • Navigation / meta-frameworks (RB-E-NAV, RB-E-META-FRAMEWORKS) — Solito and Expo Router shape how routing is shared web↔native.
  • Architecture depth — package boundaries, dependency direction, and what may import what are owned by engineering-principles.

In one paragraph

Don't try to "write once, run anywhere"; share by layer. Extract a platform-agnostic logic + state + data package first — the cheap, certain, reversible win. Defer shared UI until you need it, and when you do, bet new work on React Strict DOM or Expo Universal Components, not on react-native-web (now maintenance-only). Only an organisation that can gate agent-maintained duplicate native code has a real alternative: share the spec, not the code. Honor platform UI conventions rather than flattening them. This layered discipline is precisely the duplication react-brain is built to help teams collapse.


See also: RB-E-STATE & RB-E-DATA (the layers that share cleanly), RB-E-STYLING (React Strict DOM as a styling strategy), RB-E-NAV / RB-E-META-FRAMEWORKS (shared routing). Architecture depth: the engineering-principles skill.