Making code reusable and shareable

A while back on my current project we had to scrap a large portion of the code (pivot!), and I was tasked with the cleanup. It was painful yet cathartic to cut out tens of thousands of lines of code (new record for me!).

One thing that we wanted to salvage however, was a table component that I had created earlier in the year, that had a sticky column that the rows could scroll behind. It could be useful for other projects in the future, and oddly enough, there weren’t a ton of React Native sticky table libraries available to choose from.

I wasn’t totally sure how to go about making this component shareable. My first thought was to publish it as a package on NPM, but the code needed to be private, and publishing a private package required a paid NPM account.

After talking with my coworkers, it turned out that there was a simple solution to the sharing problem. I could create a private repo in our company Github, and any of my coworkers that had access to the repo would be able to use the package. Yes! This solution avoided all the privacy and access issues I was trying to figure out earlier.

So basically I created a new repo under my company’s GH organization. I moved the following files from my original project to a new src folder: a cleaned up sticky table component file, the mocks file, the types file, and image assets. I added an index.js file where I exported the table component. Then I pulled together a README which explained the background of the component.

Setting up the package.json seemed simple enough, but I got stuck on a few spots – including referencing the correct dependencies, and naming the package version correctly. I don’t remember exactly what was off, but I think I was using “v1.0”. Eventually I switched the name to “v1.0.0” and it worked!

Anyways, I was really happy that I was able to save this code (my baby!), and even happier that it was pretty simple to share code.

Scroll To Top