search

Home  >  Q&A  >  body text

Share React components between projects

Conceptual issues. I have two projects running on two different React services. Many components can be shared between the two projects. How should I set this up so that I can have a "live" project with shared components, and multiple projects can use these components in real time. Through searching, I learned that it can be achieved through npm packages and installed, but will this eliminate real-time performance? Is there a way that components can be developed as independent projects and multiple projects can be developed together.

P粉225961749P粉225961749429 days ago663

reply all(1)I'll reply

  • P粉970736384

    P粉9707363842023-09-21 13:43:59

    To create a shared component, we can create another repository on Git and convert it into a library. You can then use this as a package for your own share-c.

    Here are a few steps you can try...

    1. Add the private git repository as a dependency.

    2. Specify the branch below

      git https://github.com/username/repository.git#branch-name

    3. Open your package.json file and add dependencies like this.

      "dependencies": { "packageName": "git https://github.com/username/repository.git#branch-name" }

    4. Run npm install

    It should be helpful...

    reply
    0
  • Cancelreply