Skip to content
+91-7795206615
|
info@habilelabs.io

  • Home
  • About
  • Services
    • Custom Application Development
    • UI/UX Designing
    • Web Application Development
    • Offshore Product Services
    • Technical Outsourcing
    • ERP Services
  • Company
    • Careers
    • Case Studies
  • Specialization
    • Frontend Frameworks
      • Angular
      • ReactJS
      • VueJS
      • HTML / CSS
      • Javascript /Jquery
      • Bootstrap
      • Material design
    • Backend Frameworks
      • NodeJS
      • Meteor
      • GraphQL
      • Loopback
      • Salesforce
      • Spring Boot
      • Odoo
      • Laravel
    • Database / ORM
      • MySQL
      • PostgreSQL
      • Oracle
      • MongoDB
      • Google Firebase
      • Mongoose
      • Sequelize
      • Hibernate / JPA
    • Languages
      • Java Script
      • Dot Net
      • Java
      • Python
      • C / C++
      • PHP
      • AI / ML
      • Type Script
    • Mobile Frameworks
      • Ionic
      • Native Script
      • Native Android App
      • Native iOS App
      • Google Flutter
      • React Native
  • Blog
  • Hire Us

Monorepo for React Native Apps with Nx

Categories

  • Angular
  • Business Strategies
  • Cloud Services
  • CRM
  • Design Pattern
  • E-commerce
  • ERP Applications
  • Javascript
  • Meteor
  • Mobile development
  • Mongo DB
  • Node JS
  • Odoo
  • Our Partners
  • PHP
  • React
  • SAAS
  • Salesforce
  • SAP
  • Selenium
  • Tech stack Migration
  • Testing
  • UI-UX Design
  • Uncategorized
  • VAPT
  • Visualforce
  • Web Development
  • Web Security

Categories

  • Angular
  • Business Strategies
  • Cloud Services
  • CRM
  • Design Pattern
  • E-commerce
  • ERP Applications
  • Javascript
  • Meteor
  • Mobile development
  • Mongo DB
  • Node JS
  • Odoo
  • Our Partners
  • PHP
  • React
  • SAAS
  • Salesforce
  • SAP
  • Selenium
  • Tech stack Migration
  • Testing
  • UI-UX Design
  • Uncategorized
  • VAPT
  • Visualforce
  • Web Development
  • Web Security
monorepo-for-react-native-apps

Hey Developers,

I am a React Native Developer and received one project with two different applications, having similar business logics and UI designs. And then I realized, there will be some duplicate or redundant code in both applications, and as a developer, we should follow DRY (Don’t Repeat Yourself) principle.

That’s why, I started looking for an architecture to avoid duplicate code across the projects. And then I came across one of the most popular options to do so – MONOREPO.

In this article, You will see how you can use multiple applications with React Native in one Monorepo-

What is Monorepo ?

Firstly, let’s understand the term Monorepo –

Simply said, it is a repository that contains code for many projects and packages.

Monorepo allows you to have multiple projects share common dependencies instead of installing the dependencies for each of them, while simplifying code sharing between projects, allowing you to import code from one package to another and Redux logic.

Great! Now that we got the concept straight, let’s start implementation using Nx.

Steps to Create A Mono-repo Project

Nx is a smart, fast and extensible build system with first class monorepo support and powerful integrations.

Now, let’s make the project structure –

👉 Create a Nx workspace-

  • To create a NX workspace, run-

npx create-nx-workspace <your_app_name> --preset=react-native

  • Go to the workspace-

cd <your_app_name>

  • To generate another application, run:

nx generate application <your_app_name>

This should generate <your_app> folder under apps.

NX Workspace

Now you can install the starter project of Nx React Native. If you run:

  • nx run-android <your-app-name>, it should launch the app in the Android simulator.
  • nx run-ios <your-app-name>, it should launch the app in the iOS simulator.

For server start, you can run:

  • nx start <your-app-name>, it will start the server for the particular app.

👉 Create a Common Library

To create a common library, where you keep common code/logics for both the applications:

nx generate lib <your_lib_name>

This should generate <your_lib> folder under libs.

👉 Create a Common Component for both apps

There can be some common components as well that are used across both React Native apps.

  • For that, create a library called ui and create a component:

nx generate lib ui

nx generate component <your-component-name> --project=ui --export

This generates the folder <your-component-name> under ui/src/lib.

Now you can write your common UI code in the above component and use this component in both the application in app.js.

If you run nx run-ios <your-app-name> and nx run-android <your-app-name>, you should see something like this:

React Native App

Conclusion

Congratulations! You have created React Native mobile apps. 🎉🎉

Nx + React Native is a powerful tool that allows you to have multiple mobile applications code in the same repo with shared business logic.

For Source code, you can check the Github repo.

For more such insightful blogs, stay tuned!

Happy Coding!😊

Posted byMuskan JainMay 19, 2022May 19, 2022Posted inMobile development, React, UI-UX Design, Web DevelopmentTags: mobile app development, Momorepo, NX, React Native, React Native App

Post navigation


:

Leave a comment

Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Cross-Database with Association in Postgres with Sequelize

    Cross-Database with Association in Postgres with Sequelize

  • How can You Improve Your Communication Skills – Effective Tips

    How can You Improve Your Communication Skills – Effective Tips

  • 5 Reasons that Make CRM Software Beneficial for Every Business

    5 Reasons that Make CRM Software Beneficial for Every Business

  • Do Low-Code Solutions have a Future in Web Development?

    Do Low-Code Solutions have a Future in Web Development?

  • A Revenue Management Reset in Consumer Goods

    A Revenue Management Reset in Consumer Goods

  • “Empowering your right-side brain” – Increasing Creativity

    “Empowering your right-side brain” – Increasing Creativity

Talk to our experts now

Have a project or looking for development team? Contact us.

Get a quote

About Us

Habilelabs Private Limited is the ISO 9001:2015 certified IT company, which has marked its flagship in 20+ countries with 100+ projects successfully

Company

  • About
  • Blog
  • Careers
  • Hire Us
  • Privacy Policy

Contact Us

  • +91-9828247415
  • +91-9887992695
  • info@habilelabs.io

Follow Us

Office

  • Habilelabs Private Limited
    4th Floor, I.G.M. School Campus,
    Sec-93 Agarwal Farm, Mansarovar,
    Jaipur, Rajasthan India
    Pin:302020