100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
React Native
30 minintermediate

Monorepos, Shared Code and Web Reuse

A monorepo promises that your React Native app and your web app can share code — but 'can share code' and 'should share this specific piece of code' are different questions, and teams that skip the second one end up with either a bloated shared package full of things that silently break on one platform, or a monorepo in name only where nothing is actually shared and the tooling overhead bought nothing.

Metro, React Native's bundler, was built assuming a single package's node_modules, and pointing it at a workspace root where dependencies are hoisted across multiple packages is a real configuration problem, not a solved default — module resolution failures inside a freshly created monorepo are common enough that most teams hit at least one before their first successful build.

This lesson draws the actual line: what genuinely ports across React Native and web with no platform-specific behavior (business logic, validation, typed API clients, design tokens), what needs a platform-specific implementation behind a shared interface (anything touching native storage, camera, gestures), and how the build tooling has to be configured for either to actually resolve correctly.

Analogy🏏Cricket
🏏 Think of it like cricket: A team touring both Australia and India in the same year doesn't select two entirely separate squads that share nothing, nor does it send the exact same starting XI with the exact same tactics to both tours — the actual approach shares the underlying talent pool and the core game plan (the batting order's general approach, the team's fitness and fielding standards) while adapting specific tactics to conditions: four seamers and a flatter length in Australia, more spin and fuller lines on Indian turners. A think tank that tried to share literally everything — bowling seam position, field settings, the exact same XI — would get thrashed on one tour or the other, because conditions genuinely differ in ways that matter. A think tank that shared nothing, rebuilding strategy from scratch for each tour, would waste the deep, expensive work of building a coherent team identity that should transfer everywhere. A monorepo faces the identical choice: business logic, validation rules, and API clients are the team's core game plan — they transfer cleanly regardless of platform. Camera access, native gestures, and platform-specific navigation are the seam position and field settings — they need a platform-specific implementation behind a shared interface. The insight is that good code sharing, like good touring strategy, is deliberate about which layer is universal and which layer adapts, not an all-or-nothing bet in either direction.
Lesson 33 of 35
0% complete