The Problem That Made Me Write This

Every time I tried to put Re.Pack, Module Federation and Redux together in a React Native app, I ended up in the same place: three great docs, each one explaining its own tool, and none of them explaining how they work together.

  • The Re.Pack docs explain Module Federation, but do not say where each piece of code should live.
  • The Module Federation docs explain singleton and eager, but say nothing about shared state.
  • The Redux docs explain the store, but assume there is a single bundle.

And it is exactly in the middle of those three that things break.

That is why I wrote a guide that puts the pieces together, with code, from start to finish.

First, What Is a Super App?

It is a single app in the store, built from several independent parts. Each part, the mini app, is made by one team and published without a new store release. The app installed on the phone, the host, downloads each mini app when the user opens that tab.

If you come from Metro or Expo, the first question is: why can't you do this with Metro? Because Metro puts all the JS into a single bundle. It cannot load, at runtime, code that came from another build, or share libs between those builds. Re.Pack replaces Metro and brings Module Federation, which does exactly those two things.

An Error Everybody Runs Into

Let's go to an example. This is a mini app config that looks right:

new Repack.plugins.ModuleFederationPluginV2({ exposes: { './App': './src/App' }, name: 'news', shared: { react: { eager: false, singleton: true }, 'react-native': { eager: false, singleton: true } } }) 

The app opens, the mini app tab loads and...

could not find react-redux context value; please ensure the component is wrapped in a <Provider> 

But the <Provider> is right there, in the host! What happened? react-redux is not in shared. So the mini app brought its own copy, with a context different from the host's. The host's <Provider> lives in one context, and the mini app's useSelector looks in the other.

Let's fix it. Instead of each package building its own shared by hand, the list lives in one place, inside the SDK:

[ "react", "react-native", "react-redux", "@reduxjs/toolkit", "@my-org/sdk" ] 

And the host and the mini apps generate shared from it:

new Repack.plugins.ModuleFederationPluginV2({ exposes: { './App': './src/App' }, name: 'news', shared: getSharedDependencies({ eager: false }) }) 

One list, one source of truth, and the error is gone. Simpler, right? That is the kind of thing the guide covers: the problem, why it happens and how to stop falling into it.

What Is in the Docs

There are 9 chapters, in three languages:

  • 0. Concepts: what a super app is, Re.Pack vs Metro, a Module Federation glossary and the path from tapping the icon to the mini app on screen. The starting point if you have never used Re.Pack.
  • 1. Architecture: the roles of host, mini apps and SDK, who can import from whom, how the host loads a mini app and how to run everything in dev.
  • 2. Singletons: the single list of shared libs and why eager only goes in the host.
  • 3. One store: Redux Toolkit with the duck pattern, slices injected at runtime by each mini app and selectors without pointless re-renders.
  • 4. Thunks and API: where each API call lives (SDK or mini app) and complete screen + duck + API examples, in a mini app and in the host.
  • 5. Versions: runtimeVersion and requiredVersion explained together, with a table of when to bump and a story from start to finish.
  • 6. Separate repositories: what changes when each mini app lives in its own git repo.
  • 7. TypeScript with aliases: @/ in the host and in the mini apps, and why the SDK cannot use it.
  • 8. Rules and checklist: everything summed up for code review.

What You Can Do With It

  • Split a React Native app into a host, mini apps and an SDK without any of them importing the others.
  • Have a single Redux store, with each mini app injecting its own state when it loads.
  • Publish a mini app to the CDN without breaking people who still have the old APK.
  • Know, before the merge, whether a change requires a new APK.
  • Choose between a monorepo and one repository per mini app, knowing the cost of each.

Conclusion

None of these tools is hard on its own. The hard part is the space between them, and that is where an app in production breaks. Study how the pieces fit together, not just each piece on its own.

The guide is open and lives on GitHub, in English, Portuguese and Spanish:

Official Docs