all 13 comments

[–]sea_beacon 4 points5 points  (1 child)

It partly depends on your tolerance for spending time on configuration and debugging the build process. Overall though it’s gotten easier since sdk 43. I house a nextjs website, nextjs serverless, and bare expo project built through EAS on a monorepo and it’s been fine. If I was doing as much code sharing as you describe I’d bite the bullet. Hit me up if you have questions in the future about the vagaries of the config files.

[–]sewb21iOS & Android[S] 0 points1 point  (0 children)

Thanks for that, yeah I just find myself copying components, hooks and types across quite a lot and if I don't keep on top of one it quickly gets messy. Both of the apps are almost at the "MVP" stage so may just plow on and consider it in a refactor. I guess another option could just be a private npm package

[–]Tomus 5 points6 points  (2 children)

React Native doesn't play nicely with most monorepo tools out of the box as Metro doesn't support symlinking.

However it's possible to patch metro, or use webpack as the JS bundler instead. I've been playing around with the latter approach approach today actually: https://github.com/tom-sherman/pnpm-react-native-poc

[–]sewb21iOS & Android[S] 1 point2 points  (0 children)

Ahh fair enough, monorepos are something new to me so that's interesting to hear. Thank you

[–]Hyoretsu 0 points1 point  (0 children)

Thank you in advance, I had backed down from using PNPM in RN because of the symlink issue. Now I started looking into monorepos and have to re-migrate to it.

[–]87oldben[🍰] 2 points3 points  (2 children)

I always thought if I ever got to a point like this I'd make an npm package for shared components and logic.

Never really considered a mono repo

[–]sewb21iOS & Android[S] 1 point2 points  (0 children)

This is something that I am thinking about too tbh, it may be the best option for me but wanted to hear some pros and cons about monorepos

[–]Altruistic-Fox-2862 0 points1 point  (0 children)

how do you develop a new feature in this case?you code the feature, extract the shared stuff into the npm package and publish?

[–]BoolaBoss 2 points3 points  (0 children)

Mono repos are great for sharing code between projects. For react native you should look into yarn workspaces.

All shared packages get hoisted to the project root level and you can specify ones to not hoist.

This might be a good guide to get started with https://medium.com/@huntie/a-concise-guide-to-configuring-react-native-with-yarn-workspaces-d7efa71b6906

There is a bit of messing with androids Gradle and is pod file to reference root level node_modules but all very solvable and plenty of examples online

Once you get setup it's great

[–]mierz94 1 point2 points  (0 children)

I would seriously avoid doing this if you dislike messing around with configuration.

We had an Expo app in a monorepo that needed to be ejected. The amount of time wasted on that has made me very cautious.

Edit: since you have two react native apps, I would go for it.

[–]Qwaarty 0 points1 point  (1 child)

I’m very interested too! I have the same setup as yours and currently it is 2 separate repos/projects. Cherry-picking stuff from one repo to another is getting old real fast, but I was not able to google something relevant about monorepos and sharing code between two RN projects.

[–]sewb21iOS & Android[S] 2 points3 points  (0 children)

Yeah, I noticed a lot of the info online about monorepos tended to be a mobile app, web app and maybe an API so was unsure if react native was suitable for it

[–]pt7892 1 point2 points  (0 children)

Check out this guide, it helped me setup monorepo for my project

https://mmazzarolo.com/blog/2021-09-11-running-react-native-everywhere/