Question: I am creating several mobile applications in react-native that share common components. I have difficulties handling the dependencies. Here is what I do, which is tedious, is there a better way?

* A repository "common-modules" has shared components
* Several repositories include the common one as a dependency like this:

### Package.json

```
"dependencies": {
    "common-components": "file:../common-components"
},

```

I use it like that in the different apps:

```
import XXX from 'common-components/src/...'

```

Now this is great because all other dependencies are in "common-components", but as soon as one of them has native code, I am forced to link the library again in each app.

For instance, if I use "react-native-image-picker", I have to install it again in each application and link it in XCode, edit build.gradle etc. etc.

* It takes forever
* Are my linked dependencies bundled twice?
* I fear the day when I must change/upgrade one of them...

Is there a better way?

Answer: 
I've heard of projects that share code being managed in a monorepo. That may help managing shared code but won't solve the problem of linking native modules N times for N apps.

However, there is `react-native link` that should automate the process, and ease linking the native modules a lot. Note there is no need to re-link if you just upgrade a native dependency.

Alternatively, I think it should be possible to wrap multiple native modules into one. If you take a look at [MainReactPackage.java](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java) in RN repo, it wraps several native modules. I imagine similar mechanism can be employed on iOS, with static libraries. Obviously, this means that it won't be easy to selectively include some modules and others not.
Like you said yourself it is easier to work with a duplicated codebase. To deal with that you can create your own package manager for your shared components. Make a script for each component which will add it's dependencies to package.json and configure gradle and XCode. Add a simple GUI to include your components with a single click.

This may seem like a lot of work upfront, but:
- you will keep full control
- once you have a script to install a component you will save time each time you use it on a new app
- in the case of updates you can create a script to handle that as well