React Native NPM Module Setup (Locally)

Curious about building your own React Native Component Module library but don’t know where to start? Well this resource will get you started.

Steps:

  1. Create new Component Module Folder your custom modules folder in your project. (Create one if it does not exist (e.g. customModules)).
  2. Using terminal, cd to the new Component Module folder you just created.
  3. Init the npm by typing: npm init. Answer all the questions.
  4. Create an index.js file. This file is the entry point for your module. Create a normal React Native Module here. (Don’t forget to export as normal) (E.g. export default function FunctionName ())
  5. Add parent dependencies for the module by adding “peerDependencies” in the package.json. Example: “react” : “^17.0.1”, “react-native”: “^0.64.3”.
  6. Import component using the path to the customModule.
  7. After testing, follow next post for preparing for NPM uploading.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: