I have two react Apps that I want to keep separate. However, many of the components are very similar between the two apps.
What is the best approach for sharing components?
Here are some approaches I can think of:
thanks
If the components "may vary slightly" then maybe you should duplicate them. But if you can find a way to keep them the same (and keep variations in props passed in), here how I've done it:
I setup a separate project that has all common components. There are two ways I've accessed those components from the server build system:
npm
module, and add to package.json
like any other npm module (read more about private modules here)package.json
. You'll need to have the ssh key saved on your build system so it can login to github or bitbucket (or whatever) to checkout your code.If you go with option 2, you can include repos in your package.json like this. Then when npm install
is run, it will ask for a credentials to your private repo (or it can use an ssh key).
...
"dependencies": {
...
"your-common-module": "git+ssh://[email protected]/path/to-repo.git#0.1.5"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With